Skip to content

Commit 8bff562

Browse files
committed
used PHP 7.1 features
1 parent b963fb5 commit 8bff562

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

src/Utils/DateTime.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ class DateTime extends \DateTime implements \JsonSerializable
2020
use Nette\SmartObject;
2121

2222
/** minute in seconds */
23-
const MINUTE = 60;
23+
public const MINUTE = 60;
2424

2525
/** hour in seconds */
26-
const HOUR = 60 * self::MINUTE;
26+
public const HOUR = 60 * self::MINUTE;
2727

2828
/** day in seconds */
29-
const DAY = 24 * self::HOUR;
29+
public const DAY = 24 * self::HOUR;
3030

3131
/** week in seconds */
32-
const WEEK = 7 * self::DAY;
32+
public const WEEK = 7 * self::DAY;
3333

3434
/** average month in seconds */
35-
const MONTH = 2629800;
35+
public const MONTH = 2629800;
3636

3737
/** average year in seconds */
38-
const YEAR = 31557600;
38+
public const YEAR = 31557600;
3939

4040

4141
/**

src/Utils/Image.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,28 @@ class Image
9292
use Nette\SmartObject;
9393

9494
/** {@link resize()} only shrinks images */
95-
const SHRINK_ONLY = 0b0001;
95+
public const SHRINK_ONLY = 0b0001;
9696

9797
/** {@link resize()} will ignore aspect ratio */
98-
const STRETCH = 0b0010;
98+
public const STRETCH = 0b0010;
9999

100100
/** {@link resize()} fits in given area so its dimensions are less than or equal to the required dimensions */
101-
const FIT = 0b0000;
101+
public const FIT = 0b0000;
102102

103103
/** {@link resize()} fills given area so its dimensions are greater than or equal to the required dimensions */
104-
const FILL = 0b0100;
104+
public const FILL = 0b0100;
105105

106106
/** {@link resize()} fills given area exactly */
107-
const EXACT = 0b1000;
107+
public const EXACT = 0b1000;
108108

109109
/** image types */
110-
const
110+
public const
111111
JPEG = IMAGETYPE_JPEG,
112112
PNG = IMAGETYPE_PNG,
113113
GIF = IMAGETYPE_GIF,
114114
WEBP = 18; // IMAGETYPE_WEBP is available as of PHP 7.1
115115

116-
const EMPTY_GIF = "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;";
116+
public const EMPTY_GIF = "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;";
117117

118118
private static $formats = [self::JPEG => 'jpeg', self::PNG => 'png', self::GIF => 'gif', self::WEBP => 'webp'];
119119

@@ -272,7 +272,7 @@ public function resize($width, $height, int $flags = self::FIT)
272272
return $this->resize($width, $height, self::FILL)->crop('50%', '50%', $width, $height);
273273
}
274274

275-
list($newWidth, $newHeight) = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
275+
[$newWidth, $newHeight] = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
276276

277277
if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) { // resize
278278
$newImage = static::fromBlank($newWidth, $newHeight, self::RGB(0, 0, 0, 127))->getImageResource();
@@ -363,7 +363,7 @@ public static function calculateSize(int $srcWidth, int $srcHeight, $newWidth, $
363363
*/
364364
public function crop($left, $top, $width, $height)
365365
{
366-
list($r['x'], $r['y'], $r['width'], $r['height'])
366+
[$r['x'], $r['y'], $r['width'], $r['height']]
367367
= static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
368368
$this->image = imagecrop($this->image, $r);
369369
return $this;

src/Utils/Json.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ final class Json
1919
{
2020
use Nette\StaticClass;
2121

22-
const FORCE_ARRAY = 0b0001;
22+
public const FORCE_ARRAY = 0b0001;
2323

24-
const PRETTY = 0b0010;
24+
public const PRETTY = 0b0010;
2525

2626

2727
/**

src/Utils/Object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function extensionMethod($name, $callback = null)
102102
if (strpos($name, '::') === false) {
103103
$class = get_called_class();
104104
} else {
105-
list($class, $name) = explode('::', $name);
105+
[$class, $name] = explode('::', $name);
106106
$class = (new \ReflectionClass($class))->getName();
107107
}
108108
if ($callback === null) {

src/Utils/ObjectHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function getMagicProperties(string $class): array
9999
);
100100

101101
$props = [];
102-
foreach ($matches as list(, $type, $name)) {
102+
foreach ($matches as [, $type, $name]) {
103103
$uname = ucfirst($name);
104104
$write = $type !== '-read'
105105
&& $rc->hasMethod($nm = 'set' . $uname)

src/Utils/ObjectMixin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function call($_this, string $name, array $args)
4040
throw new MemberAccessException("Call to class '$class' method without name.");
4141

4242
} elseif ($isProp === 'event') { // calling event handlers
43-
if (is_array($_this->$name) || $_this->$name instanceof \Traversable) {
43+
if (is_iterable($_this->$name)) {
4444
foreach ($_this->$name as $handler) {
4545
$handler(...$args);
4646
}
@@ -52,7 +52,7 @@ public static function call($_this, string $name, array $args)
5252
return ($_this->$name)(...$args);
5353

5454
} elseif (($methods = &self::getMethods($class)) && isset($methods[$name]) && is_array($methods[$name])) { // magic @methods
55-
list($op, $rp, $type) = $methods[$name];
55+
[$op, $rp, $type] = $methods[$name];
5656
if (count($args) !== ($op === 'get' ? 0 : 1)) {
5757
throw new Nette\InvalidArgumentException("$class::$name() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');
5858

@@ -206,7 +206,7 @@ public static function getMagicMethods(string $class): array
206206
()~mx', (string) $rc->getDocComment(), $matches, PREG_SET_ORDER);
207207

208208
$methods = [];
209-
foreach ($matches as list(, $op, $prop, $bracket, $type)) {
209+
foreach ($matches as [, $op, $prop, $bracket, $type]) {
210210
if ($bracket !== '(') {
211211
trigger_error("Bracket must be immediately after @method $op$prop() in class $class.", E_USER_WARNING);
212212
}

src/Utils/Reflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private static function fetch(&$tokens, $take)
278278
{
279279
$res = null;
280280
while ($token = current($tokens)) {
281-
list($token, $s) = is_array($token) ? $token : [$token, $token];
281+
[$token, $s] = is_array($token) ? $token : [$token, $token];
282282
if (in_array($token, (array) $take, true)) {
283283
$res .= $s;
284284
} elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], true)) {

src/Utils/SmartObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __call(string $name, array $args)
3030
$class = get_class($this);
3131

3232
if (ObjectHelpers::hasProperty($class, $name) === 'event') { // calling event handlers
33-
if (is_array($this->$name) || $this->$name instanceof \Traversable) {
33+
if (is_iterable($this->$name)) {
3434
foreach ($this->$name as $handler) {
3535
$handler(...$args);
3636
}

src/Utils/Strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Strings
2020
{
2121
use Nette\StaticClass;
2222

23-
const TRIM_CHARACTERS = " \t\n\r\0\x0B\u{A0}";
23+
public const TRIM_CHARACTERS = " \t\n\r\0\x0B\u{A0}";
2424

2525

2626
/**

src/Utils/Validators.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static function is($value, string $expected): bool
119119
continue;
120120
}
121121

122-
list($type) = $item = explode(':', $item, 2);
122+
[$type] = $item = explode(':', $item, 2);
123123
if (isset(static::$validators[$type])) {
124124
if (!static::$validators[$type]($value)) {
125125
continue;

0 commit comments

Comments
 (0)