-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added backslash to PHP internal functions
- Loading branch information
1 parent
5654b23
commit 89bc2a5
Showing
7 changed files
with
47 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Author: Nil Portugués Calderó <[email protected]> | ||
* Date: 8/18/15 | ||
* Time: 11:19 PM | ||
* Time: 11:19 PM. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
|
@@ -15,7 +15,8 @@ | |
trait JsonApiResponseTrait | ||
{ | ||
/** | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
* | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
protected function addHeaders(\Psr\Http\Message\ResponseInterface $response) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Author: Nil Portugués Calderó <[email protected]> | ||
* Date: 10/16/15 | ||
* Time: 8:59 PM | ||
* Time: 8:59 PM. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
|
@@ -19,7 +19,7 @@ class Mapper extends \NilPortugues\Api\Mapping\Mapper | |
*/ | ||
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Author: Nil Portugués Calderó <[email protected]> | ||
* Date: 10/16/15 | ||
* Time: 8:59 PM | ||
* Time: 8:59 PM. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
|
@@ -17,8 +17,7 @@ | |
use ReflectionMethod; | ||
|
||
/** | ||
* Class MappingFactory | ||
* @package NilPortugues\Laravel5\JsonApiSerializer\Mapper | ||
* Class MappingFactory. | ||
*/ | ||
class MappingFactory extends \NilPortugues\Api\Mapping\MappingFactory | ||
{ | ||
|
@@ -34,12 +33,12 @@ class MappingFactory extends \NilPortugues\Api\Mapping\MappingFactory | |
*/ | ||
protected static function getClassProperties($className) | ||
{ | ||
if (class_exists($className, true)) { | ||
if (\class_exists($className, true)) { | ||
$reflection = new ReflectionClass($className); | ||
$value = $reflection->newInstanceWithoutConstructor(); | ||
$value = $reflection->newInstanceWithoutConstructor(); | ||
|
||
if (is_subclass_of($value, Model::class, true)) { | ||
$attributes = array_merge( | ||
if (\is_subclass_of($value, Model::class, true)) { | ||
$attributes = \array_merge( | ||
Schema::getColumnListing($value->getTable()), | ||
self::getRelationshipMethodsAsPropertyName($value, $className, $reflection) | ||
); | ||
|
@@ -48,7 +47,6 @@ protected static function getClassProperties($className) | |
|
||
return self::$eloquentClasses[$className]; | ||
} | ||
|
||
} | ||
|
||
return parent::getClassProperties($className); | ||
|
@@ -65,25 +63,22 @@ protected static function getRelationshipMethodsAsPropertyName($value, $classNam | |
{ | ||
$methods = []; | ||
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { | ||
|
||
if (ltrim($method->class, "\\") === ltrim($className, "\\")) { | ||
|
||
$name = $method->name; | ||
if (\ltrim($method->class, '\\') === \ltrim($className, '\\')) { | ||
$name = $method->name; | ||
$reflectionMethod = $reflection->getMethod($name); | ||
|
||
// Eloquent relations do not include parameters, so we'll be filtering based on this criteria. | ||
if (0 == $reflectionMethod->getNumberOfParameters()) { | ||
try { | ||
$returned = $reflectionMethod->invoke($value); | ||
//All operations (eg: boolean operations) are now filtered out. | ||
if (is_object($returned)) { | ||
if (\is_object($returned)) { | ||
|
||
// Only keep those methods as properties if these are returning Eloquent relations. | ||
// But do not run the operation as it is an expensive operation. | ||
if (false !== strpos(get_class($returned), 'Illuminate\Database\Eloquent\Relations')) { | ||
if (false !== \strpos(\get_class($returned), 'Illuminate\Database\Eloquent\Relations')) { | ||
$methods[] = $method->name; | ||
} | ||
|
||
} | ||
} catch (ErrorException $e) { | ||
} | ||
|