Skip to content

Commit 67aed48

Browse files
committed
Added backslash to PHP internal functions
1 parent c6c1ca2 commit 67aed48

25 files changed

+89
-81
lines changed

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
"zendframework/zend-diactoros": "^1.1.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "4.4.*",
23-
"fabpot/php-cs-fixer": "^1.9",
22+
"phpunit/phpunit": "5.*",
23+
"fabpot/php-cs-fixer": "~1.9",
24+
"nilportugues/php_backslasher": "~0.2",
2425
"mmoreram/php-formatter": "dev-master",
2526
"satooshi/php-coveralls": "dev-master"
2627
},

src/Http/Message/AbstractResponse.php

+1
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\Api\Http\Message;
1213

1314
use Psr\Http\Message\ResponseInterface;

src/Mapping/Mapper.php

+3-17
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\Api\Mapping;
1213

1314
/**
@@ -31,7 +32,7 @@ class Mapper
3132
*/
3233
public function __construct(array $mappings = null)
3334
{
34-
if (is_array($mappings)) {
35+
if (\is_array($mappings)) {
3536
foreach ($mappings as $mappedClass) {
3637
$mapping = $this->buildMapping($mappedClass);
3738

@@ -48,7 +49,7 @@ public function __construct(array $mappings = null)
4849
*/
4950
protected function buildMapping($mappedClass)
5051
{
51-
return (is_string($mappedClass) && class_exists($mappedClass, true)) ?
52+
return (\is_string($mappedClass) && \class_exists($mappedClass, true)) ?
5253
MappingFactory::fromClass($mappedClass) :
5354
MappingFactory::fromArray($mappedClass);
5455
}
@@ -68,19 +69,4 @@ public function setClassMap(array $array)
6869
{
6970
$this->classMap = $array;
7071
}
71-
72-
/**
73-
* @param string $firstClass
74-
* @param string $secondClass
75-
*
76-
* @return bool
77-
*/
78-
private function isSubclass($firstClass, $secondClass)
79-
{
80-
if ($firstClass === $secondClass) {
81-
return false;
82-
}
83-
84-
return is_subclass_of($firstClass, $secondClass, true) || is_subclass_of($secondClass, $firstClass, true);
85-
}
8672
}

src/Mapping/Mapping.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,25 @@ public function addPropertyAlias($propertyName, $propertyAlias)
138138
*/
139139
private function updatePropertyMappings($propertyName, $propertyAlias)
140140
{
141-
if (in_array($propertyName, $this->idProperties)) {
142-
$position = array_search($propertyName, $this->idProperties, true);
141+
if (\in_array($propertyName, $this->idProperties)) {
142+
$position = \array_search($propertyName, $this->idProperties, true);
143143
$this->idProperties[$position] = $propertyAlias;
144144
}
145145

146-
$search = sprintf('{%s}', $propertyName);
147-
$replace = sprintf('{%s}', $propertyAlias);
146+
$search = \sprintf('{%s}', $propertyName);
147+
$replace = \sprintf('{%s}', $propertyAlias);
148148

149-
$this->selfUrl = str_replace($search, $replace, $this->selfUrl);
150-
$this->resourceUrlPattern = str_replace($search, $replace, $this->resourceUrlPattern);
151-
$this->otherUrls = str_replace($search, $replace, $this->otherUrls);
149+
$this->selfUrl = \str_replace($search, $replace, $this->selfUrl);
150+
$this->resourceUrlPattern = \str_replace($search, $replace, $this->resourceUrlPattern);
151+
$this->otherUrls = \str_replace($search, $replace, $this->otherUrls);
152152
}
153153

154154
/**
155155
* @param array $properties
156156
*/
157157
public function setPropertyNameAliases(array $properties)
158158
{
159-
$this->aliasedProperties = array_merge($this->aliasedProperties, $properties);
159+
$this->aliasedProperties = \array_merge($this->aliasedProperties, $properties);
160160

161161
foreach ($this->aliasedProperties as $propertyName => $propertyAlias) {
162162
$this->updatePropertyMappings($propertyName, $propertyAlias);
@@ -199,7 +199,7 @@ public function getHiddenProperties()
199199
*/
200200
public function setHiddenProperties(array $hidden)
201201
{
202-
$this->hiddenProperties = array_merge($this->hiddenProperties, $hidden);
202+
$this->hiddenProperties = \array_merge($this->hiddenProperties, $hidden);
203203
}
204204

205205
/**

src/Mapping/MappingException.php

+1
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\Api\Mapping;
1213

1314
/**

src/Mapping/MappingFactory.php

+16-15
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\Api\Mapping;
1213

1314
use NilPortugues\Api\Mappings\ApiMapping;
@@ -50,14 +51,14 @@ public static function fromClass($className)
5051
$className = '\\'.ltrim($className, '\\');
5152
if (!class_exists($className, true)) {
5253
throw new MappingException(
53-
sprintf('Provided class %s could not be loaded.', $className)
54+
\sprintf('Provided class %s could not be loaded.', $className)
5455
);
5556
}
5657
$instance = new $className();
5758

58-
if (!in_array(ApiMapping::class, class_implements($instance, true))) {
59+
if (!in_array(ApiMapping::class, \class_implements($instance, true))) {
5960
throw new MappingException(
60-
sprintf('Class %s must implement %s.', ltrim($className, '\\'), ApiMapping::class)
61+
\sprintf('Class %s must implement %s.', \ltrim($className, '\\'), ApiMapping::class)
6162
);
6263
}
6364

@@ -70,11 +71,11 @@ public static function fromClass($className)
7071
static::URLS_KEY => $instance->getUrls(),
7172
];
7273

73-
if (in_array(HalJsonMapping::class, class_implements($instance, true))) {
74+
if (\in_array(HalJsonMapping::class, \class_implements($instance, true))) {
7475
$mappedClass[static::CURIES_KEY] = $instance->getCuries();
7576
}
7677

77-
if (in_array(JsonApiMapping::class, class_implements($instance, true))) {
78+
if (\in_array(JsonApiMapping::class, \class_implements($instance, true))) {
7879
$mappedClass[static::RELATIONSHIPS_KEY] = $instance->getRelationships();
7980
}
8081

@@ -167,10 +168,10 @@ protected static function setAliasedProperties(array &$mappedClass, Mapping $map
167168
{
168169
if (false === empty($mappedClass[static::ALIASED_PROPERTIES_KEY])) {
169170
$mapping->setPropertyNameAliases($mappedClass[static::ALIASED_PROPERTIES_KEY]);
170-
foreach (array_keys($mapping->getAliasedProperties()) as $propertyName) {
171-
if (false === in_array($propertyName, static::getClassProperties($className), true)) {
171+
foreach (\array_keys($mapping->getAliasedProperties()) as $propertyName) {
172+
if (false === \in_array($propertyName, static::getClassProperties($className), true)) {
172173
throw new MappingException(
173-
sprintf(
174+
\sprintf(
174175
'Could not alias property %s in class %s because it does not exist.',
175176
$propertyName,
176177
$className
@@ -203,11 +204,11 @@ protected static function getClassProperties($className)
203204

204205
if ($parentClass = $ref->getParentClass()) {
205206
$parentPropsArr = static::getClassProperties($parentClass->getName());
206-
if (count($parentPropsArr) > 0) {
207-
$properties = array_merge($parentPropsArr, $properties);
207+
if (\count($parentPropsArr) > 0) {
208+
$properties = \array_merge($parentPropsArr, $properties);
208209
}
209210
}
210-
static::$classProperties[$className] = array_keys($properties);
211+
static::$classProperties[$className] = \array_keys($properties);
211212
}
212213

213214
return static::$classProperties[$className];
@@ -225,9 +226,9 @@ protected static function setHideProperties(array &$mappedClass, Mapping $mappin
225226
if (false === empty($mappedClass[static::HIDE_PROPERTIES_KEY])) {
226227
$mapping->setHiddenProperties($mappedClass[static::HIDE_PROPERTIES_KEY]);
227228
foreach ($mapping->getHiddenProperties() as $propertyName) {
228-
if (false === in_array($propertyName, static::getClassProperties($className), true)) {
229+
if (false === \in_array($propertyName, static::getClassProperties($className), true)) {
229230
throw new MappingException(
230-
sprintf(
231+
\sprintf(
231232
'Could not hide property %s in class %s because it does not exist.',
232233
$propertyName,
233234
$className
@@ -249,9 +250,9 @@ protected static function setRelationships(array &$mappedClass, Mapping $mapping
249250
{
250251
if (!empty($mappedClass[static::RELATIONSHIPS_KEY])) {
251252
foreach ($mappedClass[static::RELATIONSHIPS_KEY] as $propertyName => $urls) {
252-
if (false === in_array($propertyName, static::getClassProperties($className))) {
253+
if (false === \in_array($propertyName, static::getClassProperties($className))) {
253254
throw new MappingException(
254-
sprintf(
255+
\sprintf(
255256
'Could not find property %s in class %s because it does not exist.',
256257
$propertyName,
257258
$className

src/Transformer/Helpers/RecursiveDeleteHelper.php

+6-5
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\Api\Transformer\Helpers;
1213

1314
use NilPortugues\Serializer\Serializer;
@@ -28,7 +29,7 @@ public static function deleteKeys(array &$array, array $unwantedKey)
2829
self::unsetKeys($array, $unwantedKey);
2930

3031
foreach ($array as &$value) {
31-
if (is_array($value)) {
32+
if (\is_array($value)) {
3233
self::deleteKeys($value, $unwantedKey);
3334
}
3435
}
@@ -51,7 +52,7 @@ private static function deleteNextLevelProperties(
5152
foreach ($array as $key => &$value) {
5253
if (!in_array($key, $deletions, true)) {
5354
$newArray[$key] = $value;
54-
if (is_array($newArray[$key])) {
55+
if (\is_array($newArray[$key])) {
5556
self::deleteProperties($mappings, $newArray[$key], $typeKey);
5657
}
5758
}
@@ -67,7 +68,7 @@ private static function deleteNextLevelProperties(
6768
*/
6869
public static function deleteProperties(array &$mappings, array &$array, $typeKey)
6970
{
70-
if (array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
71+
if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
7172
$newArray = [];
7273

7374
self::deleteMatchedClassProperties($mappings, $array, $typeKey, $newArray);
@@ -87,7 +88,7 @@ public static function deleteProperties(array &$mappings, array &$array, $typeKe
8788
private static function deleteMatchedClassProperties(array &$mappings, array &$array, $typeKey, array &$newArray)
8889
{
8990
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];
90-
if (is_scalar($type) && $type === $typeKey) {
91+
if (\is_scalar($type) && $type === $typeKey) {
9192
$deletions = $mappings[$typeKey]->getHiddenProperties();
9293
if (!empty($deletions)) {
9394
self::deleteNextLevelProperties($mappings, $array, $typeKey, $deletions, $newArray);
@@ -102,7 +103,7 @@ private static function deleteMatchedClassProperties(array &$mappings, array &$a
102103
private static function unsetKeys(array &$array, array &$unwantedKey)
103104
{
104105
foreach ($unwantedKey as $key) {
105-
if (array_key_exists($key, $array)) {
106+
if (\array_key_exists($key, $array)) {
106107
unset($array[$key]);
107108
}
108109
}

src/Transformer/Helpers/RecursiveFilterHelper.php

+6-5
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\Api\Transformer\Helpers;
1213

1314
use NilPortugues\Serializer\Serializer;
@@ -26,7 +27,7 @@ final class RecursiveFilterHelper
2627
*/
2728
public static function deletePropertiesNotInFilter(array &$mappings, array &$array, $typeKey)
2829
{
29-
if (array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
30+
if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
3031
$newArray = [];
3132
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];
3233

@@ -52,7 +53,7 @@ private static function deleteMatchedClassNotInFilterProperties(
5253
$type,
5354
array &$newArray
5455
) {
55-
if (is_scalar($type) && $type === $typeKey) {
56+
if (\is_scalar($type) && $type === $typeKey) {
5657
$keepKeys = $mappings[$typeKey]->getFilterKeys();
5758
$idProperties = $mappings[$typeKey]->getIdProperties();
5859

@@ -81,7 +82,7 @@ private static function filterKeys(
8182
foreach ($array as $key => &$value) {
8283
if (self::isPreservableKey($key, $keepKeys, $idProperties)) {
8384
$newArray[$key] = $value;
84-
if (is_array($newArray[$key])) {
85+
if (\is_array($newArray[$key])) {
8586
self::deletePropertiesNotInFilter($mappings, $newArray[$key], $typeKey);
8687
}
8788
}
@@ -98,7 +99,7 @@ private static function filterKeys(
9899
private static function isPreservableKey($key, $keepKeys, $idProperties)
99100
{
100101
return $key == Serializer::CLASS_IDENTIFIER_KEY
101-
|| (in_array($key, $keepKeys, true)
102-
|| in_array($key, $idProperties, true));
102+
|| (\in_array($key, $keepKeys, true)
103+
|| \in_array($key, $idProperties, true));
103104
}
104105
}

0 commit comments

Comments
 (0)