Completed
Pull Request — master (#338)
by
unknown
05:18
created

ModuleRepository::install()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Addon\Module;
2
3
use Anomaly\Streams\Platform\Addon\Module\Contract\ModuleRepositoryInterface;
4
5
/**
6
 * Class ModuleRepository
7
 *
8
 * @link   http://pyrocms.com/
9
 * @author PyroCMS, Inc. <[email protected]>
10
 * @author Ryan Thompson <[email protected]>
11
 */
12
class ModuleRepository implements ModuleRepositoryInterface
13
{
14
15
    /**
16
     * The module model.
17
     *
18
     * @var
19
     */
20
    protected $model;
21
22
    /**
23
     * Create a new ModuleRepository instance.
24
     *
25
     * @param ModuleModel $model
26
     */
27
    public function __construct(ModuleModel $model)
28
    {
29
        $this->model = $model;
30
    }
31
32
    /**
33
     * Return all modules in the database.
34
     *
35
     * @return mixed
36
     */
37
    public function all()
38
    {
39
        return $this->model->all();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->model->all(); of type Illuminate\Database\Eloq...base\Eloquent\Builder[] adds the type Illuminate\Database\Eloquent\Builder[] to the return on line 39 which is incompatible with the return type declared by the interface Anomaly\Streams\Platform...epositoryInterface::all of type Anomaly\Streams\Platform\Model\EloquentCollection.
Loading history...
40
    }
41
42
    /**
43
     * Create a module record.
44
     *
45
     * @param  Module $module
46
     * @return bool
47
     */
48
    public function create(Module $module)
49
    {
50
        $instance = $this->model->newInstance();
51
52
        $instance->namespace = $module->getNamespace();
0 ignored issues
show
Documentation introduced by
The property namespace does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
53
        $instance->installed = false;
0 ignored issues
show
Documentation introduced by
The property installed does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
54
        $instance->enabled   = false;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
55
56
        return $instance->save();
57
    }
58
59
    /**
60
     * Delete a module record.
61
     *
62
     * @param  Module      $module
63
     * @return ModuleModel
64
     */
65
    public function delete(Module $module)
66
    {
67
        $module = $this->model->findByNamespace($module->getNamespace());
68
69
        if ($module) {
70
            $module->delete();
71
        }
72
73
        return $module;
74
    }
75
76
    /**
77
     * Mark a module as installed.
78
     *
79
     * @param  Module $module
80
     * @return bool
81
     */
82
    public function install(Module $module)
83
    {
84
        if (!$module = $this->model->findByNamespaceOrNew($module->getNamespace())) {
85
            return false;
86
        }
87
88
        $module->installed = true;
0 ignored issues
show
Documentation introduced by
The property installed does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
89
        $module->enabled   = true;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
90
91
        return $module->save();
92
    }
93
94
    /**
95
     * Mark a module as uninstalled.
96
     *
97
     * @param  Module $module
98
     * @return bool
99
     */
100
    public function uninstall(Module $module)
101
    {
102
        if (!$module = $this->model->findByNamespace($module->getNamespace())) {
103
            return false;
104
        }
105
106
        $module->installed = false;
0 ignored issues
show
Documentation introduced by
The property installed does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
107
        $module->enabled   = false;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
108
109
        return $module->save();
110
    }
111
112
    /**
113
     * Mark a module as disabled.
114
     *
115
     * @param  Module $module
116
     * @return bool
117
     */
118
    public function disable(Module $module)
119
    {
120
        $module = $this->model->findByNamespace($module->getNamespace());
121
122
        $module->enabled = false;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
123
124
        return $module->save();
125
    }
126
127
    /**
128
     * Mark a module as enabled.
129
     *
130
     * @param  Module $module
131
     * @return bool
132
     */
133
    public function enabled(Module $module)
134
    {
135
        $module = $this->model->findByNamespace($module->getNamespace());
136
137
        $module->enabled = true;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...don\Module\ModuleModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
138
139
        return $module->save();
140
    }
141
142
    /**
143
     * Install the npm dependencies
144
     * @return void
145
     */
146
    public function installNpm()
147
    {
148
        $addProcess = new Process('npm install ' . $this->getAppPath() . ' --save');
0 ignored issues
show
Bug introduced by
The method getAppPath() does not seem to exist on object<Anomaly\Streams\P...odule\ModuleRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
149
        $addProcess->run();
150
    }
151
}
152