Completed
Push — master ( 08635e...dd4786 )
by Nil
10:03
created

MappingFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClassProperties() 0 17 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
11
namespace NilPortugues\Laravel5\JsonApi\Mapper;
12
13
use Illuminate\Database\Eloquent\Model;
14
use Illuminate\Support\Facades\Schema;
15
use ReflectionClass;
16
17
/**
18
 * Class MappingFactory.
19
 */
20
class MappingFactory extends \NilPortugues\Api\Mapping\MappingFactory
21
{
22
    /**
23
     * @var array
24
     */
25
    protected static $eloquentClasses = [];
26
27
    /**
28
     * @param string $className
29
     *
30
     * @return array
31
     */
32
    protected static function getClassProperties($className)
33
    {
34
        if (\class_exists($className, true)) {
35
            $reflection = new ReflectionClass($className);
36
            $value = $reflection->newInstanceWithoutConstructor();
37
38
            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...
39
                $attributes = Schema::getColumnListing($value->getTable());
40
41
                self::$eloquentClasses[$className] = $attributes;
42
43
                return self::$eloquentClasses[$className];
44
            }
45
        }
46
47
        return parent::getClassProperties($className);
48
    }
49
}
50