Skip to content

Commit 7d3d211

Browse files
committed
Added backslash to PHP internal functions
1 parent 3be06d9 commit 7d3d211

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+97
-60
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"symfony/yaml": "^2.7"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "4.4.*",
31+
"phpunit/phpunit": "5.*",
32+
"nilportugues/php_backslasher": "~0.2",
3233
"fabpot/php-cs-fixer": "^1.9",
3334
"mmoreram/php-formatter": "dev-master",
3435
"satooshi/php-coveralls": "dev-master",

src/DeepCopySerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer;
1213

1314
use ReflectionClass;

src/JsonSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer;
1213

1314
use NilPortugues\Serializer\Strategy\JsonStrategy;

src/Serializer.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ class Serializer
7777
*/
7878
public function __construct(StrategyInterface $strategy)
7979
{
80-
$this->isHHVM = defined('HHVM_VERSION');
80+
$this->isHHVM = \defined('HHVM_VERSION');
8181
if ($this->isHHVM) {
8282
// @codeCoverageIgnoreStart
83-
$this->serializationMap = array_merge(
83+
$this->serializationMap = \array_merge(
8484
$this->serializationMap,
85-
include realpath(dirname(__FILE__).'/Mapping/serialization_hhvm.php')
85+
include \realpath(\dirname(__FILE__).'/Mapping/serialization_hhvm.php')
8686
);
87-
$this->unserializationMapHHVM = include realpath(dirname(__FILE__).'/Mapping/unserialization_hhvm.php');
87+
$this->unserializationMapHHVM = include \realpath(\dirname(__FILE__).'/Mapping/unserialization_hhvm.php');
8888
// @codeCoverageIgnoreEnd
8989
}
9090
$this->serializationStrategy = $strategy;
@@ -142,15 +142,15 @@ protected function serializeData($value)
142142

143143
if ($this->isHHVM && ($value instanceof \DateTimeZone || $value instanceof \DateInterval)) {
144144
// @codeCoverageIgnoreStart
145-
return call_user_func_array($this->serializationMap[get_class($value)], [$this, $value]);
145+
return \call_user_func_array($this->serializationMap[get_class($value)], [$this, $value]);
146146
// @codeCoverageIgnoreEnd
147147
}
148148

149-
if (is_object($value)) {
149+
if (\is_object($value)) {
150150
return $this->serializeObject($value);
151151
}
152152

153-
$type = (gettype($value) && $value !== null) ? gettype($value) : 'string';
153+
$type = (\gettype($value) && $value !== null) ? \gettype($value) : 'string';
154154
$func = $this->serializationMap[$type];
155155

156156
return $this->$func($value);
@@ -173,7 +173,7 @@ protected function guardForUnsupportedValues($value)
173173
);
174174
}
175175

176-
if (is_resource($value)) {
176+
if (\is_resource($value)) {
177177
throw new SerializerException('Resource is not supported in Serializer');
178178
}
179179
}
@@ -187,7 +187,7 @@ protected function guardForUnsupportedValues($value)
187187
*/
188188
public function unserialize($value)
189189
{
190-
if (is_array($value) && isset($value[self::SCALAR_TYPE])) {
190+
if (\is_array($value) && isset($value[self::SCALAR_TYPE])) {
191191
return $this->unserializeData($value);
192192
}
193193

@@ -223,7 +223,7 @@ protected function unserializeData($value)
223223
return $this->unserializeObject($value);
224224
}
225225

226-
return array_map([$this, __FUNCTION__], $value);
226+
return \array_map([$this, __FUNCTION__], $value);
227227
}
228228

229229
/**
@@ -235,9 +235,9 @@ protected function getScalarValue($value)
235235
{
236236
switch ($value[self::SCALAR_TYPE]) {
237237
case 'integer':
238-
return intval($value[self::SCALAR_VALUE]);
238+
return \intval($value[self::SCALAR_VALUE]);
239239
case 'float':
240-
return floatval($value[self::SCALAR_VALUE]);
240+
return \floatval($value[self::SCALAR_VALUE]);
241241
case 'boolean':
242242
return $value[self::SCALAR_VALUE];
243243
case 'NULL':
@@ -291,7 +291,7 @@ protected function unserializeDateTimeFamilyObject(array $value, $className)
291291
if ($this->isDateTimeFamilyObject($className)) {
292292
if ($this->isHHVM) {
293293
// @codeCoverageIgnoreStart
294-
return call_user_func_array(
294+
return \call_user_func_array(
295295
$this->unserializationMapHHVM[$className],
296296
[$this, $className, $value]
297297
);
@@ -315,7 +315,7 @@ protected function isDateTimeFamilyObject($className)
315315
$isDateTime = false;
316316

317317
foreach ($this->dateTimeClassType as $class) {
318-
$isDateTime = $isDateTime || is_subclass_of($className, $class, true) || $class === $className;
318+
$isDateTime = $isDateTime || \is_subclass_of($className, $class, true) || $class === $className;
319319
}
320320

321321
return $isDateTime;
@@ -334,13 +334,13 @@ protected function restoreUsingUnserialize($className, array $attributes)
334334
}
335335

336336
$obj = (object) $attributes;
337-
$serialized = preg_replace(
337+
$serialized = \preg_replace(
338338
'|^O:\d+:"\w+":|',
339339
'O:'.strlen($className).':"'.$className.'":',
340-
serialize($obj)
340+
\serialize($obj)
341341
);
342342

343-
return unserialize($serialized);
343+
return \unserialize($serialized);
344344
}
345345

346346
/**
@@ -357,7 +357,7 @@ protected function unserializeUserDefinedObject(array $value, $className)
357357
$this->objectMapping[$this->objectMappingIndex++] = $obj;
358358
$this->setUnserializedObjectProperties($value, $ref, $obj);
359359

360-
if (method_exists($obj, '__wakeup')) {
360+
if (\method_exists($obj, '__wakeup')) {
361361
$obj->__wakeup();
362362
}
363363

@@ -393,7 +393,7 @@ protected function setUnserializedObjectProperties(array $value, ReflectionClass
393393
*/
394394
protected function serializeScalar($value)
395395
{
396-
$type = gettype($value);
396+
$type = \gettype($value);
397397
if ($type === 'double') {
398398
$type = 'float';
399399
}
@@ -411,7 +411,7 @@ protected function serializeScalar($value)
411411
*/
412412
protected function serializeArray(array $value)
413413
{
414-
if (array_key_exists(self::MAP_TYPE, $value)) {
414+
if (\array_key_exists(self::MAP_TYPE, $value)) {
415415
return $value;
416416
}
417417

@@ -455,7 +455,7 @@ protected function serializeInternalClass($value, $className, ReflectionClass $r
455455
{
456456
$paramsToSerialize = $this->getObjectProperties($ref, $value);
457457
$data = [self::CLASS_IDENTIFIER_KEY => $className];
458-
$data += array_map([$this, 'serializeData'], $this->extractObjectData($value, $ref, $paramsToSerialize));
458+
$data += \array_map([$this, 'serializeData'], $this->extractObjectData($value, $ref, $paramsToSerialize));
459459

460460
return $data;
461461
}
@@ -475,7 +475,7 @@ protected function getObjectProperties(ReflectionClass $ref, $value)
475475
$props[] = $prop->getName();
476476
}
477477

478-
return array_unique(array_merge($props, array_keys(get_object_vars($value))));
478+
return \array_unique(\array_merge($props, \array_keys(\get_object_vars($value))));
479479
}
480480

481481
/**
@@ -530,7 +530,7 @@ protected function extractAllInhertitedProperties($value, ReflectionClass $rc, a
530530
$property->setAccessible(true);
531531
$rp[$property->getName()] = $property->getValue($this);
532532
}
533-
$data = array_merge($rp, $data);
533+
$data = \array_merge($rp, $data);
534534
} while ($rc = $rc->getParentClass());
535535
}
536536
}

src/Serializer/HHVM/DatePeriodSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\HHVM;
1213

1314
/**

src/Serializer/HHVM/DateTimeImmutableSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\HHVM;
1213

1314
use NilPortugues\Serializer\Serializer;

src/Serializer/HHVM/DateTimeSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\HHVM;
1213

1314
use NilPortugues\Serializer\Serializer;

src/Serializer/InternalClasses/DateIntervalSerializer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1213

1314
use DateInterval;
@@ -72,10 +73,10 @@ protected static function getTypedValue(Serializer $serializer, array $value)
7273
public static function serialize(Serializer $serializer, DateInterval $dateInterval)
7374
{
7475
return array(
75-
Serializer::CLASS_IDENTIFIER_KEY => get_class($dateInterval),
76+
Serializer::CLASS_IDENTIFIER_KEY => \get_class($dateInterval),
7677
'construct' => array(
7778
Serializer::SCALAR_TYPE => 'string',
78-
Serializer::SCALAR_VALUE => sprintf(
79+
Serializer::SCALAR_VALUE => \sprintf(
7980
'P%sY%sM%sDT%sH%sM%sS',
8081
$dateInterval->y,
8182
$dateInterval->m,
@@ -90,7 +91,7 @@ public static function serialize(Serializer $serializer, DateInterval $dateInter
9091
Serializer::SCALAR_VALUE => (empty($dateInterval->invert)) ? 0 : 1,
9192
),
9293
'days' => array(
93-
Serializer::SCALAR_TYPE => gettype($dateInterval->days),
94+
Serializer::SCALAR_TYPE => \gettype($dateInterval->days),
9495
Serializer::SCALAR_VALUE => $dateInterval->days,
9596
),
9697
);

src/Serializer/InternalClasses/DatePeriodSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1213

1314
/**

src/Serializer/InternalClasses/DateTimeZoneSerializer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
1112
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1213

1314
use DateTimeZone;
@@ -45,7 +46,7 @@ public static function unserialize(Serializer $serializer, $className, array $va
4546
$ref = new ReflectionClass($className);
4647

4748
foreach ($value as &$v) {
48-
if (is_array($v)) {
49+
if (\is_array($v)) {
4950
$v = $serializer->unserialize($v);
5051
}
5152
}

0 commit comments

Comments
 (0)