SettingsRepository::findById()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php namespace jlourenco\base\Repositories;
2
3
use Cartalyst\Support\Traits\RepositoryTrait;
4
5
class SettingsRepository implements SettingsRepositoryInterface
6
{
7
    use RepositoryTrait;
8
9
    /**
10
     * The Settings model name.
11
     *
12
     * @var string
13
     */
14
    protected $model = 'jlourenco\base\Models\Settings';
15
16
    /**
17
     * Create a new settings repository.
18
     *
19
     * @param  string  $model
20
     */
21
    public function __construct($model = null)
22
    {
23
        if (isset($model))
24
            $this->model = $model;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function findById($id)
31
    {
32
        return $this
33
            ->createModel()
34
            ->newQuery()
35
            ->find($id);
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function findByName($name)
42
    {
43
        return $this
44
            ->createModel()
45
            ->newQuery()
46
            ->where('name', $name)
47
            ->first();
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function findByFriendlyName($name)
54
    {
55
        return $this
56
            ->createModel()
57
            ->newQuery()
58
            ->where('friendly_name', $name)
59
            ->first();
60
    }
61
62
    public function getSetting($name)
63
    {
64
        return $this->findByFriendlyName($name)->value;
0 ignored issues
show
Documentation introduced by
The property value does not exist on object<jlourenco\base\Models\Settings>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
    }
66
67
}
68