Completed
Pull Request — master (#79)
by Jacob
02:58
created

Embed   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
1
<?php
2
3
namespace As3\Modlr\Models;
4
5
use As3\Modlr\Metadata\EmbedMetadata;
6
use As3\Modlr\Persister\Record;
7
use As3\Modlr\Store\Store;
8
9
/**
10
 * Represents an embedded record fragment of a root level model.
11
 *
12
 * @author Jacob Bare <[email protected]>
13
 */
14
class Embed extends AbstractModel
15
{
16
    /**
17
     * Constructor.
18
     *
19
     * @param   EmbedMetadata   $metadata   The internal embed metadata that supports this Embed.
20
     * @param   Store           $store      The model store service for handling persistence operations.
21
     * @param   array|null      $properties The embed's properties from the db layer to init the embed with. New embeds will constructed with a null record.
22
     */
23
    public function __construct(EmbedMetadata $metadata, Store $store, array $properties = null)
24
    {
25
        parent::__construct($metadata, $store, $properties);
26
        $this->getState()->setLoaded();
27
    }
28
29
    /**
30
     * Gets the embed name.
31
     *
32
     * @api
33
     * @return  string
34
     */
35
    public function getName()
36
    {
37
        return $this->metadata->name;
0 ignored issues
show
Bug introduced by
Accessing name on the interface As3\Modlr\Metadata\Interfaces\AttributeInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
38
    }
39
}
40