Skip to content

Commit

Permalink
Bug fix (#9)
Browse files Browse the repository at this point in the history
* remove deprecated modifier

* change log

* formatting
  • Loading branch information
weiwang314 authored and gdbrown committed Mar 29, 2019
1 parent 93fd2e7 commit 36220b2
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 66 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-1.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
This changelog references the relevant changes done in 1.x versions.


## v1.1.2
* In `HashtagUtils`, remove deprecated PCRE modifier.


## v1.1.1
* Add `urlsafeB64Decode` and `urlsafeB64Encode` to `StringUtils`.

Expand Down
4 changes: 2 additions & 2 deletions src/Common/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BigNumber extends \Moontoast\Math\BigNumber implements \JsonSerializable
* BigNumber constructor.
*
* @param mixed $number
* @param null $scale
* @param null $scale
*/
public function __construct($number, $scale = null)
{
Expand All @@ -24,6 +24,6 @@ public function __construct($number, $scale = null)
*/
public function jsonSerialize()
{
return (string) $this->getValue();
return (string)$this->getValue();
}
}
8 changes: 6 additions & 2 deletions src/Common/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class Enum implements \JsonSerializable

/**
* private constructor to ensure flyweight construction.
*
* @param int|string $value
*/
final private function __construct($value)
Expand All @@ -39,6 +40,7 @@ final private function __construct($value)

/**
* @param string|int $value
*
* @return static
* @throws \UnexpectedValueException
*/
Expand Down Expand Up @@ -84,7 +86,7 @@ final public function getValue()
*/
final public function __toString()
{
return (string) $this->value;
return (string)$this->value;
}

/**
Expand Down Expand Up @@ -127,6 +129,7 @@ final public static function values()
* it to our value.
*
* @param Enum|int|string $value
*
* @return bool
*/
final public function equals($value)
Expand All @@ -141,7 +144,8 @@ final public function equals($value)
* Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
*
* @param string $name
* @param array $arguments
* @param array $arguments
*
* @return static
* @throws \BadMethodCallException
*/
Expand Down
1 change: 1 addition & 0 deletions src/Common/FromArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface FromArray
* that signature.
*
* @param array $data
*
* @return static
*/
public static function fromArray(array $data = []);
Expand Down
7 changes: 4 additions & 3 deletions src/Common/GeoPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Represents a GeoJson Point value.
* @link http://geojson.org/geojson-spec.html#point
* @link http://geojson.org/geojson-spec.html#point
*
* @deprecated Use "Gdbots\Pbj\WellKnown\GeoPoint" from "gdbots/pbj" 1.1.x or later instead.
*/
Expand All @@ -26,8 +26,8 @@ public function __construct($lat, $lon)
{
@trigger_error(sprintf('"%s" is deprecated. Use "Gdbots\Pbj\WellKnown\GeoPoint" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);

$this->latitude = (float) $lat;
$this->longitude = (float) $lon;
$this->latitude = (float)$lat;
$this->longitude = (float)$lon;

if ($this->latitude > 90.0 || $this->latitude < -90.0) {
throw new \InvalidArgumentException('Latitude must be within range [-90.0, 90.0]');
Expand Down Expand Up @@ -83,6 +83,7 @@ public function jsonSerialize()

/**
* @param string $string A string with format lat,long
*
* @return self
*/
public static function fromString($string)
Expand Down
38 changes: 21 additions & 17 deletions src/Common/Microtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* 10 digits (unix timestamp) concatenated with 6 microsecond digits.
*
* @link http://php.net/manual/en/function.microtime.php
* @link http://php.net/manual/en/function.microtime.php
*
* @deprecated Use "Gdbots\Pbj\WellKnown\Microtime" from "gdbots/pbj" 1.1.x or later instead.
*/
Expand Down Expand Up @@ -52,16 +52,17 @@ public static function create()
*
* @link http://php.net/manual/en/function.microtime.php
*
* @param float $float e.g. 1422060753.9581
* @param float $float e.g. 1422060753.9581
*
* @return self
*/
public static function fromFloat($float)
{
$str = substr(str_pad(str_replace('.', '', $float), 16, '0'), 0, 16);
$m = new self();
$m->int = (int) $str;
$m->sec = (int) substr($str, 0, 10);
$m->usec = (int) substr($str, -6);
$m->int = (int)$str;
$m->sec = (int)substr($str, 0, 10);
$m->usec = (int)substr($str, -6);
return $m;
}

Expand All @@ -72,15 +73,16 @@ public static function fromFloat($float)
* @link http://php.net/manual/en/function.gettimeofday.php
*
* @param array $tod
*
* @return self
*/
public static function fromTimeOfDay(array $tod)
{
$str = $tod['sec'] . str_pad($tod['usec'], 6, '0', STR_PAD_LEFT);
$m = new self();
$m->int = (int) $str;
$m->sec = (int) substr($str, 0, 10);
$m->usec = (int) substr($str, -6);
$m->int = (int)$str;
$m->sec = (int)substr($str, 0, 10);
$m->usec = (int)substr($str, -6);
return $m;
}

Expand All @@ -91,12 +93,13 @@ public static function fromTimeOfDay(array $tod)
* Lack of precision on digits will be automatically padded with zeroes.
*
* @param string|int $stringOrInteger
*
* @return self
* @throws \InvalidArgumentException
*/
public static function fromString($stringOrInteger)
{
$int = (int) $stringOrInteger;
$int = (int)$stringOrInteger;
$len = strlen($int);
if ($len < 13 || $len > 16) {
throw new \InvalidArgumentException(
Expand All @@ -109,13 +112,13 @@ public static function fromString($stringOrInteger)
}

if ($len < 16) {
$int = (int) str_pad($int, 16, '0');
$int = (int)str_pad($int, 16, '0');
}

$m = new self();
$m->int = $int;
$m->sec = (int) substr($int, 0, 10);
$m->usec = (int) substr($int, -6);
$m->sec = (int)substr($int, 0, 10);
$m->usec = (int)substr($int, -6);
return $m;
}

Expand All @@ -124,15 +127,16 @@ public static function fromString($stringOrInteger)
* it's timestamp and microseconds.
*
* @param \DateTime $date
*
* @return self
*/
public static function fromDateTime(\DateTime $date)
{
$str = $date->format('U') . str_pad($date->format('u'), 6, '0');
$m = new self();
$m->int = (int) $str;
$m->sec = (int) substr($str, 0, 10);
$m->usec = (int) substr($str, -6);
$m->int = (int)$str;
$m->sec = (int)substr($str, 0, 10);
$m->usec = (int)substr($str, -6);
return $m;
}

Expand All @@ -141,7 +145,7 @@ public static function fromDateTime(\DateTime $date)
*/
public function toString()
{
return (string) $this->int;
return (string)$this->int;
}

/**
Expand Down Expand Up @@ -189,6 +193,6 @@ public function toDateTime()
*/
public function toFloat()
{
return (float) ($this->sec . '.' . str_pad($this->usec, 6, '0', STR_PAD_LEFT));
return (float)($this->sec . '.' . str_pad($this->usec, 6, '0', STR_PAD_LEFT));
}
}
5 changes: 4 additions & 1 deletion src/Common/Util/ArrayUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ final class ArrayUtils
/**
* Private constructor. This class is not meant to be instantiated.
*/
private function __construct() {}
private function __construct()
{
}

/**
* Returns true if the array is associative
*
* @param array $array
*
* @return bool
*/
public static function isAssoc(array $array)
Expand Down
23 changes: 15 additions & 8 deletions src/Common/Util/ClassUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ final class ClassUtils
/**
* Private constructor. This class is not meant to be instantiated.
*/
private function __construct() {}
private function __construct()
{
}

/**
* Returns an array of all the traits that a class is using. This
Expand All @@ -26,13 +28,14 @@ private function __construct() {}
* for optimal checking on the usesTrait method.
*
* @param string|object $class
* @param bool $deep
* @param bool $autoload
* @param bool $deep
* @param bool $autoload
*
* @return array
*/
private static function loadTraits($class, $deep = true, $autoload = true)
{
$cachKey = is_object($class) ? get_class($class) : (string) $class;
$cachKey = is_object($class) ? get_class($class) : (string)$class;
$cachKey .= $deep ? ':deep' : '';
$cachKey .= $autoload ? ':autoload' : '';

Expand Down Expand Up @@ -64,8 +67,9 @@ private static function loadTraits($class, $deep = true, $autoload = true)
* includes all of the extended classes and traits by default.
*
* @param string|object $class
* @param bool $deep
* @param bool $autoload
* @param bool $deep
* @param bool $autoload
*
* @return array
*/
public static function getTraits($class, $deep = true, $autoload = true)
Expand All @@ -77,7 +81,8 @@ public static function getTraits($class, $deep = true, $autoload = true)
* Returns true if a class uses a given trait.
*
* @param string|object $class
* @param string $trait full qualified class name
* @param string $trait full qualified class name
*
* @return bool
*/
public static function usesTrait($class, $trait)
Expand All @@ -89,6 +94,7 @@ public static function usesTrait($class, $trait)
* Returns the class name of an object, without the namespace
*
* @param object|string $objectOrString
*
* @return string
*/
public static function getShortName($objectOrString)
Expand All @@ -101,10 +107,11 @@ public static function getShortName($objectOrString)
* Returns an array of CONSTANT_NAME => value for a given class
*
* @param string $className
*
* @return array
*/
public static function getConstants($className)
{
return (new \ReflectionClass($className))->getConstants();
}
}
}
16 changes: 10 additions & 6 deletions src/Common/Util/DateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
final class DateUtils
{
/**
* @link https://en.wikipedia.org/wiki/ISO_8601
* @link https://en.wikipedia.org/wiki/ISO_8601
* @const string
*/
const ISO8601_ZULU = 'Y-m-d\TH:i:s.u\Z';
Expand All @@ -28,26 +28,29 @@ final class DateUtils
/**
* Private constructor. This class is not meant to be instantiated.
*/
private function __construct() {}
private function __construct()
{
}

/**
* Returns true if it's a valid timestamp.
*
* @param string $timestamp
* @param bool $allowNegative
* @param bool $allowNegative
*
* @return bool
*/
public static function isValidTimestamp($timestamp, $allowNegative = false)
{
$timestamp = (string) $timestamp;
$timestamp = (string)$timestamp;

if ($allowNegative) {
return ((string) (int) $timestamp === $timestamp)
return ((string)(int)$timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= self::MIN_UTC_TIME);
}

return ((string) (int) $timestamp === $timestamp)
return ((string)(int)$timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= 0);
}
Expand All @@ -62,6 +65,7 @@ public static function isValidTimestamp($timestamp, $allowNegative = false)
* @link http://en.wikipedia.org/wiki/ISO_8601
*
* @param string $string
*
* @return bool
*/
public static function isValidISO8601Date($string)
Expand Down
Loading

0 comments on commit 36220b2

Please sign in to comment.