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

Embed::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
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