Skip to content

Commit 58f8417

Browse files
committed
Added backslash to PHP internal functions
1 parent 72a6ba4 commit 58f8417

34 files changed

+87
-54
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
],
1515
"require": {
1616
"php": ">=5.5.0",
17-
"nilportugues/api-transformer": "~1.2"
17+
"nilportugues/api-transformer": "~1.2",
18+
"nilportugues/php_backslasher": "^0.2.1"
1819
},
1920
"require-dev": {
2021
"phpunit/phpunit": "4.4.*",

src/HalJsonTransformer.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function serialize($value)
5555
{
5656
$this->noMappingGuard();
5757

58-
if (is_array($value) && !empty($value[Serializer::MAP_TYPE])) {
59-
$data = ['total' => count($value)];
58+
if (\is_array($value) && !empty($value[Serializer::MAP_TYPE])) {
59+
$data = ['total' => \count($value)];
6060
unset($value[Serializer::MAP_TYPE]);
6161
foreach ($value[Serializer::SCALAR_VALUE] as $v) {
6262
$data[self::EMBEDDED_KEY][] = $this->serializeObject($v);
@@ -65,7 +65,7 @@ public function serialize($value)
6565
$data = $this->serializeObject($value);
6666
}
6767

68-
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
68+
return \json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
6969
}
7070

7171
/**
@@ -117,7 +117,7 @@ private function serialization(array $data)
117117
private function setEmbeddedResources(array &$data)
118118
{
119119
foreach ($data as $propertyName => &$value) {
120-
if (is_array($value)) {
120+
if (\is_array($value)) {
121121
$this->setEmbeddedForResource($data, $value, $propertyName);
122122
$this->setEmbeddedForResourceArray($data, $value, $propertyName);
123123
}
@@ -133,11 +133,11 @@ private function setEmbeddedForResource(array &$data, array &$value, $propertyNa
133133
{
134134
if (!empty($value[Serializer::CLASS_IDENTIFIER_KEY])) {
135135
$type = $value[Serializer::CLASS_IDENTIFIER_KEY];
136-
if (is_scalar($type)) {
136+
if (\is_scalar($type)) {
137137
$idProperties = $this->mappings[$type]->getIdProperties();
138138
CuriesHelper::addCurieForResource($this->mappings, $this->curies, $type);
139139

140-
if (false === in_array($propertyName, $idProperties)) {
140+
if (false === \in_array($propertyName, $idProperties)) {
141141
$data[self::EMBEDDED_KEY][$propertyName] = $value;
142142

143143
list($idValues, $idProperties) = RecursiveFormatterHelper::getIdPropertyAndValues(
@@ -199,7 +199,7 @@ private function addEmbeddedResourceAdditionalLinks(array &$data, array &$value,
199199
$links = $data[self::EMBEDDED_KEY][$propertyName][self::LINKS_KEY];
200200
}
201201

202-
$data[self::EMBEDDED_KEY][$propertyName][self::LINKS_KEY] = array_merge(
202+
$data[self::EMBEDDED_KEY][$propertyName][self::LINKS_KEY] = \array_merge(
203203
$links,
204204
$this->addHrefToLinks($this->getResponseAdditionalLinks($value, $type))
205205
);
@@ -252,7 +252,7 @@ private function getPropertyNameWithCurie($type, $propertyName)
252252
{
253253
$curie = $this->mappings[$type]->getCuries();
254254
if (!empty($curie)) {
255-
$propertyName = sprintf(
255+
$propertyName = \sprintf(
256256
'%s:%s',
257257
$curie['name'],
258258
self::camelCaseToUnderscore($propertyName)
@@ -298,7 +298,7 @@ private function setEmbeddedForResourceArray(array &$data, array &$value, $prope
298298
{
299299
if (!empty($value[Serializer::MAP_TYPE])) {
300300
foreach ($value as &$arrayValue) {
301-
if (is_array($arrayValue)) {
301+
if (\is_array($arrayValue)) {
302302
$this->setEmbeddedArrayValue($data, $propertyName, $arrayValue);
303303
}
304304
}
@@ -334,7 +334,7 @@ private function setEmbeddedArrayValue(array &$data, $propertyName, array &$arra
334334
*/
335335
private function isResourceInArray($inArrayValue)
336336
{
337-
return is_array($inArrayValue) && !empty($inArrayValue[Serializer::CLASS_IDENTIFIER_KEY]);
337+
return \is_array($inArrayValue) && !empty($inArrayValue[Serializer::CLASS_IDENTIFIER_KEY]);
338338
}
339339

340340
/**
@@ -376,14 +376,14 @@ private function addArrayValueResourceToEmbedded(
376376
protected function setResponseLinks(array &$data)
377377
{
378378
if (!empty($data[Serializer::CLASS_IDENTIFIER_KEY])) {
379-
$data[self::LINKS_KEY] = array_merge(
379+
$data[self::LINKS_KEY] = \array_merge(
380380
CuriesHelper::buildCuries($this->curies),
381381
$this->addHrefToLinks($this->buildLinks()),
382382
(!empty($data[self::LINKS_KEY])) ? $data[self::LINKS_KEY] : [],
383383
$this->addHrefToLinks($this->getResponseAdditionalLinks($data, $data[Serializer::CLASS_IDENTIFIER_KEY]))
384384
);
385385

386-
$data[self::LINKS_KEY] = array_filter($data[self::LINKS_KEY]);
386+
$data[self::LINKS_KEY] = \array_filter($data[self::LINKS_KEY]);
387387

388388
if (empty($data[self::LINKS_KEY])) {
389389
unset($data[self::LINKS_KEY]);
@@ -429,7 +429,7 @@ private function setResponseMeta(array &$response)
429429
*/
430430
private static function buildUrl(array &$mappings, $idProperties, $idValues, $url, $type)
431431
{
432-
$outputUrl = str_replace($idProperties, $idValues, $url);
432+
$outputUrl = \str_replace($idProperties, $idValues, $url);
433433
if ($outputUrl !== $url) {
434434
return $outputUrl;
435435
}
@@ -441,8 +441,8 @@ private static function buildUrl(array &$mappings, $idProperties, $idValues, $ur
441441
}
442442

443443
$className = $mappings[$type]->getClassName();
444-
$className = explode('\\', $className);
445-
$className = array_pop($className);
444+
$className = \explode('\\', $className);
445+
$className = \array_pop($className);
446446

447447
$outputUrl = self::secondPassBuildUrl([$className], $idValues, $url);
448448
if ($outputUrl !== $url) {
@@ -494,7 +494,7 @@ private static function toCamelCase($original, $idValues, $url)
494494
$o = '{'.self::underscoreToCamelCase(self::camelCaseToUnderscore($o)).'}';
495495
}
496496

497-
return str_replace($original, $idValues, $url);
497+
return \str_replace($original, $idValues, $url);
498498
}
499499

500500
/**
@@ -508,11 +508,11 @@ private static function toLowerFirstCamelCase($original, $idValues, $url)
508508
{
509509
foreach ($original as &$o) {
510510
$o = self::underscoreToCamelCase(self::camelCaseToUnderscore($o));
511-
$o[0] = strtolower($o[0]);
511+
$o[0] = \strtolower($o[0]);
512512
$o = '{'.$o.'}';
513513
}
514514

515-
return str_replace($original, $idValues, $url);
515+
return \str_replace($original, $idValues, $url);
516516
}
517517

518518
/**
@@ -528,7 +528,7 @@ private static function toUnderScore($original, $idValues, $url)
528528
$o = '{'.self::camelCaseToUnderscore($o).'}';
529529
}
530530

531-
return str_replace($original, $idValues, $url);
531+
return \str_replace($original, $idValues, $url);
532532
}
533533

534534
/**
@@ -541,13 +541,13 @@ private static function toUnderScore($original, $idValues, $url)
541541
*/
542542
private static function camelCaseToUnderscore($camel, $splitter = '_')
543543
{
544-
$camel = preg_replace(
544+
$camel = \preg_replace(
545545
'/(?!^)[[:upper:]][[:lower:]]/',
546546
'$0',
547-
preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel)
547+
\preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel)
548548
);
549549

550-
return strtolower($camel);
550+
return \strtolower($camel);
551551
}
552552

553553
/**
@@ -559,6 +559,6 @@ private static function camelCaseToUnderscore($camel, $splitter = '_')
559559
*/
560560
private static function underscoreToCamelCase($string)
561561
{
562-
return str_replace(' ', '', ucwords(strtolower(str_replace(['_', '-'], ' ', $string))));
562+
return \str_replace(' ', '', \ucwords(\strtolower(\str_replace(['_', '-'], ' ', $string))));
563563
}
564564
}

src/Helpers/AttributeFormatterHelper.php

Lines changed: 5 additions & 4 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\Api\HalJson\Helpers;
1213

1314
use NilPortugues\Api\HalJson\HalJsonTransformer;
@@ -21,11 +22,11 @@ final class AttributeFormatterHelper
2122
*/
2223
public static function flattenObjectsWithSingleKeyScalars(array &$array)
2324
{
24-
if (1 === count($array) && is_scalar(end($array))) {
25-
$array = array_pop($array);
25+
if (1 === \count($array) && \is_scalar(\end($array))) {
26+
$array = \array_pop($array);
2627
}
2728

28-
if (is_array($array)) {
29+
if (\is_array($array)) {
2930
self::loopScalarValues($array, 'flattenObjectsWithSingleKeyScalars');
3031
}
3132
}
@@ -37,7 +38,7 @@ public static function flattenObjectsWithSingleKeyScalars(array &$array)
3738
private static function loopScalarValues(array &$array, $method)
3839
{
3940
foreach ($array as $propertyName => &$value) {
40-
if (is_array($value) && HalJsonTransformer::LINKS_KEY !== $propertyName) {
41+
if (\is_array($value) && HalJsonTransformer::LINKS_KEY !== $propertyName) {
4142
self::$method($value);
4243
}
4344
}

src/Helpers/CuriesHelper.php

Lines changed: 3 additions & 2 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\Api\HalJson\Helpers;
1213

1314
use NilPortugues\Api\HalJson\HalJsonTransformer;
@@ -22,10 +23,10 @@ final class CuriesHelper
2223
public static function buildCuries(array $curies)
2324
{
2425
$curiesArray = [];
25-
$curies = (array) array_filter($curies);
26+
$curies = (array) \array_filter($curies);
2627

2728
if (!empty($curies)) {
28-
$curiesArray = [HalJsonTransformer::LINKS_CURIES => array_values($curies)];
29+
$curiesArray = [HalJsonTransformer::LINKS_CURIES => \array_values($curies)];
2930

3031
foreach ($curiesArray[HalJsonTransformer::LINKS_CURIES] as &$value) {
3132
$value[HalJsonTransformer::LINKS_TEMPLATED_KEY] = true;

src/Http/Message/AbstractResponse.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\Api\HalJson\Http\Message;
1213

1314
abstract class AbstractResponse extends \NilPortugues\Api\Http\Message\AbstractResponse

src/Http/Message/ErrorResponse.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\Api\HalJson\Http\Message;
1213

1314
/**

src/Http/Message/ResourceCreatedResponse.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\Api\HalJson\Http\Message;
1213

1314
class ResourceCreatedResponse extends AbstractResponse

src/Http/Message/ResourceDeletedResponse.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\Api\HalJson\Http\Message;
1213

1314
class ResourceDeletedResponse extends AbstractResponse

src/Http/Message/ResourceNotFoundResponse.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\Api\HalJson\Http\Message;
1213

1314
class ResourceNotFoundResponse extends AbstractResponse

src/Http/Message/ResourcePatchErrorResponse.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\Api\HalJson\Http\Message;
1213

1314
class ResourcePatchErrorResponse extends AbstractResponse

0 commit comments

Comments
 (0)