Completed
Push — master ( fa78c0...08635e )
by Nil
05:39
created

MappingFactory::getRelationshipMethodsAsPropertyName()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 29
rs 6.7273
cc 7
eloc 14
nc 10
nop 3
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 10/16/15
5
 * Time: 8:59 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace NilPortugues\Laravel5\JsonApiSerializer\Mapper;
11
12
use Illuminate\Database\Eloquent\Model;
13
use Illuminate\Support\Facades\Schema;
14
use ReflectionClass;
15
16
/**
17
 * Class MappingFactory.
18
 */
19
class MappingFactory extends \NilPortugues\Api\Mapping\MappingFactory
20
{
21
    /**
22
     * @var array
23
     */
24
    protected static $eloquentClasses = [];
25
26
    /**
27
     * @param string $className
28
     *
29
     * @return array
30
     */
31
    protected static function getClassProperties($className)
32
    {
33
        if (\class_exists($className, true)) {
34
            $reflection = new ReflectionClass($className);
35
            $value = $reflection->newInstanceWithoutConstructor();
36
37
            if (\is_subclass_of($value, Model::class, true)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Illuminate\Database\Eloquent\Model::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
38
                $attributes = Schema::getColumnListing($value->getTable());
39
40
                self::$eloquentClasses[$className] = $attributes;
41
42
                return self::$eloquentClasses[$className];
43
            }
44
        }
45
46
        return parent::getClassProperties($className);
47
    }
48
}
49