Applied fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-08-08 12:10:28 -04:00 committed by StyleCI Bot
parent 741f166640
commit 3a0a7179d4
14 changed files with 68 additions and 32 deletions

View File

@ -11,6 +11,7 @@ If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class API extends Exception class API extends Exception
{ {
public $session; public $session;

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
* Manages connection to telegram servers. * Manages connection to telegram servers.
*/ */

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class Crypt class Crypt
{ {
public function ige_encrypt($message, $key, $iv) public function ige_encrypt($message, $key, $iv)

View File

@ -9,14 +9,16 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class DebugFunctions { class DebugFunctions
{
/** /**
* Function to dump the hex version of a string. * Function to dump the hex version of a string.
* *
* @param $what What to dump. * @param $what What to dump.
*/ */
public static function hex_dump(...$what) public static function hex_dump(...$what)
{ {
foreach ($what as $w) { foreach ($what as $w) {
@ -25,9 +27,9 @@ class DebugFunctions {
} }
/** /**
* Function to visualize byte streams. Split into bytes, print to console. * Function to visualize byte streams. Split into bytes, print to console.
* :param bs: BYTE STRING. * :param bs: BYTE STRING.
*/ */
public static function vis($bs) public static function vis($bs)
{ {
$bs = str_split($bs); $bs = str_split($bs);

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class Exception extends \Exception class Exception extends \Exception
{ {
public function __construct($message, $code = 0, Exception $previous = null) public function __construct($message, $code = 0, Exception $previous = null)
@ -21,6 +23,7 @@ class Exception extends \Exception
// make sure everything is assigned properly // make sure everything is assigned properly
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
/** /**
* ExceptionErrorHandler. * ExceptionErrorHandler.
* *
@ -32,6 +35,6 @@ class Exception extends \Exception
if (error_reporting() === 0) { if (error_reporting() === 0) {
return true; // return true to continue through the others error handlers return true; // return true to continue through the others error handlers
} }
throw new Exception($errstr.' on line '.$errline.' of file '.$errfile, $errno); throw new self($errstr.' on line '.$errline.' of file '.$errfile, $errno);
} }
} }

View File

@ -12,10 +12,14 @@ If not, see <http://www.gnu.org/licenses/>.
/* /*
* Logging class * Logging class
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class Logging {
class Logging
{
public $mode = null; public $mode = null;
public $optional = null; public $optional = null;
/* /*
* Constructor function * Constructor function
* Accepts various logging modes: * Accepts various logging modes:
@ -24,11 +28,14 @@ class Logging {
* 2 - Log to file defined in second parameter * 2 - Log to file defined in second parameter
* 3 - Echo logs * 3 - Echo logs
*/ */
public function __construct($mode, $optional = null){ public function __construct($mode, $optional = null)
$this->mode = (string)$mode; {
$this->mode = (string) $mode;
$this->optional = $optional; $this->optional = $optional;
} }
public function __invoke(...$params){
public function __invoke(...$params)
{
foreach ($params as $param) { foreach ($params as $param) {
switch ($this->mode) { switch ($this->mode) {
case '1': case '1':
@ -38,15 +45,17 @@ class Logging {
error_log($param, 3, $this->optional); error_log($param, 3, $this->optional);
break; break;
case '3': case '3':
echo $param . PHP_EOL; echo $param.PHP_EOL;
break; break;
default: default:
break; break;
} }
} }
} }
public function log(...$params) {
if($this->mode == null) { public function log(...$params)
{
if ($this->mode == null) {
$mode = array_pop($params); $mode = array_pop($params);
} else { } else {
$mode = $this->mode; $mode = $this->mode;
@ -60,7 +69,7 @@ class Logging {
error_log($param, 3, $this->optional); error_log($param, 3, $this->optional);
break; break;
case '3': case '3':
echo $param . PHP_EOL; echo $param.PHP_EOL;
break; break;
default: default:
break; break;

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class PrimeModule class PrimeModule
{ {
public function __construct() public function __construct()

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class RSA extends TL\TL class RSA extends TL\TL
{ {
public $key; // phpseclib\Crypt\RSA class public $key; // phpseclib\Crypt\RSA class
@ -25,13 +27,14 @@ class RSA extends TL\TL
$this->n = $this->key->modulus; $this->n = $this->key->modulus;
$this->e = $this->key->exponent; $this->e = $this->key->exponent;
$this->fp = new \phpseclib\Math\BigInteger(strrev(substr(sha1($this->serialize_param('bytes', $this->n->toBytes()) . $this->serialize_param('bytes', $this->e->toBytes()), true), -8)), -256); $this->fp = new \phpseclib\Math\BigInteger(strrev(substr(sha1($this->serialize_param('bytes', $this->n->toBytes()).$this->serialize_param('bytes', $this->e->toBytes()), true), -8)), -256);
$this->fp_float = (float) $this->fp->toString(); $this->fp_float = (float) $this->fp->toString();
} }
public function encrypt($data) public function encrypt($data)
{ {
$bigintdata = new \phpseclib\Math\BigInteger($data, 256); $bigintdata = new \phpseclib\Math\BigInteger($data, 256);
return $bigintdata->powMod($this->e, $this->n)->toBytes(); return $bigintdata->powMod($this->e, $this->n)->toBytes();
} }
} }

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
* Manages encryption and message frames. * Manages encryption and message frames.
*/ */
@ -40,7 +42,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
-----END RSA PUBLIC KEY-----', -----END RSA PUBLIC KEY-----',
'logging' => 1, 'logging' => 1,
'logging_param' => '/tmp/MadelineProto.log', 'logging_param' => '/tmp/MadelineProto.log',
'logging' => 3 'logging' => 3,
]; ];
foreach ($default_settings as $key => $param) { foreach ($default_settings as $key => $param) {
if (!isset($settings[$key])) { if (!isset($settings[$key])) {
@ -65,9 +67,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->tl = new TL\TL(__DIR__.'/TL_schema.JSON'); $this->tl = new TL\TL(__DIR__.'/TL_schema.JSON');
} }
// Istantiate logging class // Istantiate logging class
$this->log = new Logging($this->settings["logging"], $this->settings["logging_param"]); $this->log = new Logging($this->settings['logging'], $this->settings['logging_param']);
// Set some defaults // Set some defaults
$this->auth_key = $this->settings["auth_key"]; $this->auth_key = $this->settings['auth_key'];
$this->number = 0; $this->number = 0;
$this->timedelta = 0; $this->timedelta = 0;
$this->session_id = \phpseclib\Crypt\Random::string(8); $this->session_id = \phpseclib\Crypt\Random::string(8);
@ -193,12 +195,12 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
} }
$pq_bytes = $ResPQ['pq']; $pq_bytes = $ResPQ['pq'];
foreach ($ResPQ['server_public_key_fingerprints'] as $curfp) { foreach ($ResPQ['server_public_key_fingerprints'] as $curfp) {
if($curfp === $this->key->fp_float) { if ($curfp === $this->key->fp_float) {
$public_key_fingerprint = $curfp; $public_key_fingerprint = $curfp;
break; break;
} }
} }
if(!isset($public_key_fingerprint)) { if (!isset($public_key_fingerprint)) {
throw new Exception("Handshake: couldn't find our key in the server_public_key_fingerprints vector."); throw new Exception("Handshake: couldn't find our key in the server_public_key_fingerprints vector.");
} }

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto\TL; namespace danog\MadelineProto\TL;
class TL class TL
{ {
public function __construct($filename) public function __construct($filename)
@ -39,7 +41,7 @@ class TL
if (isset($this->constructor_type[$type_])) { if (isset($this->constructor_type[$type_])) {
$tl_constructor = $this->constructor_type[$type_]; $tl_constructor = $this->constructor_type[$type_];
} else { } else {
throw new Exception('Could not extract type: ' . $type_); throw new Exception('Could not extract type: '.$type_);
} }
$bytes_io .= \danog\PHP\Struct::pack('<i', $tl_constructor->id); $bytes_io .= \danog\PHP\Struct::pack('<i', $tl_constructor->id);
foreach ($tl_constructor->params as $arg) { foreach ($tl_constructor->params as $arg) {
@ -55,7 +57,7 @@ class TL
if (isset($this->method_name[$type_])) { if (isset($this->method_name[$type_])) {
$tl_method = $this->method_name[$type_]; $tl_method = $this->method_name[$type_];
} else { } else {
throw new Exception('Could not extract type: ' . $type_); throw new Exception('Could not extract type: '.$type_);
} }
$bytes_io .= \danog\PHP\Struct::pack('<i', $tl_method->id); $bytes_io .= \danog\PHP\Struct::pack('<i', $tl_method->id);
foreach ($tl_method->params as $arg) { foreach ($tl_method->params as $arg) {
@ -179,7 +181,7 @@ class TL
if (isset($this->constructor_id[$i])) { if (isset($this->constructor_id[$i])) {
$tl_elem = $this->constructor_id[$i]; $tl_elem = $this->constructor_id[$i];
} else { } else {
throw new Exception('Could not extract type: ' . $type_); throw new Exception('Could not extract type: '.$type_);
} }
} }

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto\TL; namespace danog\MadelineProto\TL;
class TLConstructor class TLConstructor
{ {
public function __construct($json_dict) public function __construct($json_dict)

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto\TL; namespace danog\MadelineProto\TL;
class TLMethod class TLMethod
{ {
public function __construct($json_dict) public function __construct($json_dict)

View File

@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the MadelineProto. You should have received a copy of the GNU General Public License along with the MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto\TL; namespace danog\MadelineProto\TL;
class TLObject extends \ArrayObject class TLObject extends \ArrayObject
{ {
public function __construct($tl_elem) public function __construct($tl_elem)

View File

@ -11,6 +11,7 @@ If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
* Some tools. * Some tools.
*/ */
@ -60,6 +61,7 @@ class Tools
return $res; return $res;
} }
// taken from mochikit: range( [start,] stop[, step] ) // taken from mochikit: range( [start,] stop[, step] )
public static function range($start, $stop = null, $step = 1) public static function range($start, $stop = null, $step = 1)
{ {