ShorthandProperties   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A expandAlias() 0 17 4
1
<?php
2
3
namespace Silk\Type;
4
5
trait ShorthandProperties
6
{
7
    protected $object;
8
9
    /**
10
     * Expands an alias into its respective object property name.
11
     *
12
     * @param string $key  Alias key
13
     *
14
     * @return mixed|string
15
     */
16
    protected function expandAlias($key)
17
    {
18
        $aliased = $this->getAliasedObject();
0 ignored issues
show
Bug introduced by
It seems like getAliasedObject() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        /** @scrutinizer ignore-call */ 
19
        $aliased = $this->getAliasedObject();
Loading history...
19
20
        if (is_object($aliased) || ! empty(static::OBJECT_TYPE)) {
0 ignored issues
show
Bug introduced by
The constant Silk\Type\ShorthandProperties::OBJECT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
            /**
22
             * Automatically alias shorthand syntax for type_name
23
             * Eg: 'post_content' is aliased to 'content'
24
             */
25
            $expanded = static::OBJECT_TYPE . '_' . $key;
26
27
            if (property_exists($aliased, $expanded)) {
28
                return $expanded;
29
            }
30
        }
31
32
        return parent::expandAlias($key);
33
    }
34
}
35