Skip to content

Commit

Permalink
Added backslash to PHP internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Nov 2, 2015
1 parent c6c1ca2 commit 67aed48
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 81 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"zendframework/zend-diactoros": "^1.1.0"
},
"require-dev": {
"phpunit/phpunit": "4.4.*",
"fabpot/php-cs-fixer": "^1.9",
"phpunit/phpunit": "5.*",
"fabpot/php-cs-fixer": "~1.9",
"nilportugues/php_backslasher": "~0.2",
"mmoreram/php-formatter": "dev-master",
"satooshi/php-coveralls": "dev-master"
},
Expand Down
1 change: 1 addition & 0 deletions src/Http/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Http\Message;

use Psr\Http\Message\ResponseInterface;
Expand Down
20 changes: 3 additions & 17 deletions src/Mapping/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Mapping;

/**
Expand All @@ -31,7 +32,7 @@ class Mapper
*/
public function __construct(array $mappings = null)
{
if (is_array($mappings)) {
if (\is_array($mappings)) {
foreach ($mappings as $mappedClass) {
$mapping = $this->buildMapping($mappedClass);

Expand All @@ -48,7 +49,7 @@ public function __construct(array $mappings = null)
*/
protected function buildMapping($mappedClass)
{
return (is_string($mappedClass) && class_exists($mappedClass, true)) ?
return (\is_string($mappedClass) && \class_exists($mappedClass, true)) ?
MappingFactory::fromClass($mappedClass) :
MappingFactory::fromArray($mappedClass);
}
Expand All @@ -68,19 +69,4 @@ public function setClassMap(array $array)
{
$this->classMap = $array;
}

/**
* @param string $firstClass
* @param string $secondClass
*
* @return bool
*/
private function isSubclass($firstClass, $secondClass)
{
if ($firstClass === $secondClass) {
return false;
}

return is_subclass_of($firstClass, $secondClass, true) || is_subclass_of($secondClass, $firstClass, true);
}
}
18 changes: 9 additions & 9 deletions src/Mapping/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,25 @@ public function addPropertyAlias($propertyName, $propertyAlias)
*/
private function updatePropertyMappings($propertyName, $propertyAlias)
{
if (in_array($propertyName, $this->idProperties)) {
$position = array_search($propertyName, $this->idProperties, true);
if (\in_array($propertyName, $this->idProperties)) {
$position = \array_search($propertyName, $this->idProperties, true);
$this->idProperties[$position] = $propertyAlias;
}

$search = sprintf('{%s}', $propertyName);
$replace = sprintf('{%s}', $propertyAlias);
$search = \sprintf('{%s}', $propertyName);
$replace = \sprintf('{%s}', $propertyAlias);

$this->selfUrl = str_replace($search, $replace, $this->selfUrl);
$this->resourceUrlPattern = str_replace($search, $replace, $this->resourceUrlPattern);
$this->otherUrls = str_replace($search, $replace, $this->otherUrls);
$this->selfUrl = \str_replace($search, $replace, $this->selfUrl);
$this->resourceUrlPattern = \str_replace($search, $replace, $this->resourceUrlPattern);
$this->otherUrls = \str_replace($search, $replace, $this->otherUrls);
}

/**
* @param array $properties
*/
public function setPropertyNameAliases(array $properties)
{
$this->aliasedProperties = array_merge($this->aliasedProperties, $properties);
$this->aliasedProperties = \array_merge($this->aliasedProperties, $properties);

foreach ($this->aliasedProperties as $propertyName => $propertyAlias) {
$this->updatePropertyMappings($propertyName, $propertyAlias);
Expand Down Expand Up @@ -199,7 +199,7 @@ public function getHiddenProperties()
*/
public function setHiddenProperties(array $hidden)
{
$this->hiddenProperties = array_merge($this->hiddenProperties, $hidden);
$this->hiddenProperties = \array_merge($this->hiddenProperties, $hidden);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Mapping;

/**
Expand Down
31 changes: 16 additions & 15 deletions src/Mapping/MappingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Mapping;

use NilPortugues\Api\Mappings\ApiMapping;
Expand Down Expand Up @@ -50,14 +51,14 @@ public static function fromClass($className)
$className = '\\'.ltrim($className, '\\');
if (!class_exists($className, true)) {
throw new MappingException(
sprintf('Provided class %s could not be loaded.', $className)
\sprintf('Provided class %s could not be loaded.', $className)
);
}
$instance = new $className();

if (!in_array(ApiMapping::class, class_implements($instance, true))) {
if (!in_array(ApiMapping::class, \class_implements($instance, true))) {
throw new MappingException(
sprintf('Class %s must implement %s.', ltrim($className, '\\'), ApiMapping::class)
\sprintf('Class %s must implement %s.', \ltrim($className, '\\'), ApiMapping::class)
);
}

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

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

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

Expand Down Expand Up @@ -167,10 +168,10 @@ protected static function setAliasedProperties(array &$mappedClass, Mapping $map
{
if (false === empty($mappedClass[static::ALIASED_PROPERTIES_KEY])) {
$mapping->setPropertyNameAliases($mappedClass[static::ALIASED_PROPERTIES_KEY]);
foreach (array_keys($mapping->getAliasedProperties()) as $propertyName) {
if (false === in_array($propertyName, static::getClassProperties($className), true)) {
foreach (\array_keys($mapping->getAliasedProperties()) as $propertyName) {
if (false === \in_array($propertyName, static::getClassProperties($className), true)) {
throw new MappingException(
sprintf(
\sprintf(
'Could not alias property %s in class %s because it does not exist.',
$propertyName,
$className
Expand Down Expand Up @@ -203,11 +204,11 @@ protected static function getClassProperties($className)

if ($parentClass = $ref->getParentClass()) {
$parentPropsArr = static::getClassProperties($parentClass->getName());
if (count($parentPropsArr) > 0) {
$properties = array_merge($parentPropsArr, $properties);
if (\count($parentPropsArr) > 0) {
$properties = \array_merge($parentPropsArr, $properties);
}
}
static::$classProperties[$className] = array_keys($properties);
static::$classProperties[$className] = \array_keys($properties);
}

return static::$classProperties[$className];
Expand All @@ -225,9 +226,9 @@ protected static function setHideProperties(array &$mappedClass, Mapping $mappin
if (false === empty($mappedClass[static::HIDE_PROPERTIES_KEY])) {
$mapping->setHiddenProperties($mappedClass[static::HIDE_PROPERTIES_KEY]);
foreach ($mapping->getHiddenProperties() as $propertyName) {
if (false === in_array($propertyName, static::getClassProperties($className), true)) {
if (false === \in_array($propertyName, static::getClassProperties($className), true)) {
throw new MappingException(
sprintf(
\sprintf(
'Could not hide property %s in class %s because it does not exist.',
$propertyName,
$className
Expand All @@ -249,9 +250,9 @@ protected static function setRelationships(array &$mappedClass, Mapping $mapping
{
if (!empty($mappedClass[static::RELATIONSHIPS_KEY])) {
foreach ($mappedClass[static::RELATIONSHIPS_KEY] as $propertyName => $urls) {
if (false === in_array($propertyName, static::getClassProperties($className))) {
if (false === \in_array($propertyName, static::getClassProperties($className))) {
throw new MappingException(
sprintf(
\sprintf(
'Could not find property %s in class %s because it does not exist.',
$propertyName,
$className
Expand Down
11 changes: 6 additions & 5 deletions src/Transformer/Helpers/RecursiveDeleteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Transformer\Helpers;

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

foreach ($array as &$value) {
if (is_array($value)) {
if (\is_array($value)) {
self::deleteKeys($value, $unwantedKey);
}
}
Expand All @@ -51,7 +52,7 @@ private static function deleteNextLevelProperties(
foreach ($array as $key => &$value) {
if (!in_array($key, $deletions, true)) {
$newArray[$key] = $value;
if (is_array($newArray[$key])) {
if (\is_array($newArray[$key])) {
self::deleteProperties($mappings, $newArray[$key], $typeKey);
}
}
Expand All @@ -67,7 +68,7 @@ private static function deleteNextLevelProperties(
*/
public static function deleteProperties(array &$mappings, array &$array, $typeKey)
{
if (array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
$newArray = [];

self::deleteMatchedClassProperties($mappings, $array, $typeKey, $newArray);
Expand All @@ -87,7 +88,7 @@ public static function deleteProperties(array &$mappings, array &$array, $typeKe
private static function deleteMatchedClassProperties(array &$mappings, array &$array, $typeKey, array &$newArray)
{
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];
if (is_scalar($type) && $type === $typeKey) {
if (\is_scalar($type) && $type === $typeKey) {
$deletions = $mappings[$typeKey]->getHiddenProperties();
if (!empty($deletions)) {
self::deleteNextLevelProperties($mappings, $array, $typeKey, $deletions, $newArray);
Expand All @@ -102,7 +103,7 @@ private static function deleteMatchedClassProperties(array &$mappings, array &$a
private static function unsetKeys(array &$array, array &$unwantedKey)
{
foreach ($unwantedKey as $key) {
if (array_key_exists($key, $array)) {
if (\array_key_exists($key, $array)) {
unset($array[$key]);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/Transformer/Helpers/RecursiveFilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Api\Transformer\Helpers;

use NilPortugues\Serializer\Serializer;
Expand All @@ -26,7 +27,7 @@ final class RecursiveFilterHelper
*/
public static function deletePropertiesNotInFilter(array &$mappings, array &$array, $typeKey)
{
if (array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
if (\array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $array)) {
$newArray = [];
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];

Expand All @@ -52,7 +53,7 @@ private static function deleteMatchedClassNotInFilterProperties(
$type,
array &$newArray
) {
if (is_scalar($type) && $type === $typeKey) {
if (\is_scalar($type) && $type === $typeKey) {
$keepKeys = $mappings[$typeKey]->getFilterKeys();
$idProperties = $mappings[$typeKey]->getIdProperties();

Expand Down Expand Up @@ -81,7 +82,7 @@ private static function filterKeys(
foreach ($array as $key => &$value) {
if (self::isPreservableKey($key, $keepKeys, $idProperties)) {
$newArray[$key] = $value;
if (is_array($newArray[$key])) {
if (\is_array($newArray[$key])) {
self::deletePropertiesNotInFilter($mappings, $newArray[$key], $typeKey);
}
}
Expand All @@ -98,7 +99,7 @@ private static function filterKeys(
private static function isPreservableKey($key, $keepKeys, $idProperties)
{
return $key == Serializer::CLASS_IDENTIFIER_KEY
|| (in_array($key, $keepKeys, true)
|| in_array($key, $idProperties, true));
|| (\in_array($key, $keepKeys, true)
|| \in_array($key, $idProperties, true));
}
}
Loading

0 comments on commit 67aed48

Please sign in to comment.