Code Duplication    Length = 93-93 lines in 2 locations

src/Addon/Extension/ExtensionModel.php 1 location

@@ 15-107 (lines=93) @@
12
 * @author  PyroCMS, Inc. <[email protected]>
13
 * @author  Ryan Thompson <[email protected]>
14
 */
15
class ExtensionModel extends EloquentModel implements ExtensionInterface
16
{
17
18
    /**
19
     * Define the table name.
20
     *
21
     * @var string
22
     */
23
    protected $table = 'addons_extensions';
24
25
    /**
26
     * Disable timestamps for extensions.
27
     *
28
     * @var bool
29
     */
30
    public $timestamps = false;
31
32
    /**
33
     * Boot the model
34
     */
35
    protected static function boot()
36
    {
37
        self::observe(app(EloquentObserver::class));
38
39
        parent::boot();
40
    }
41
42
    /**
43
     * Find a extension by it's namespace or return a new
44
     * extension with the given namespace.
45
     *
46
     * @param  $namespace
47
     * @return ExtensionModel
48
     */
49
    public function findByNamespaceOrNew($namespace)
50
    {
51
        $extension = $this->findByNamespace($namespace);
52
53
        if ($extension instanceof ExtensionModel) {
54
            return $extension;
55
        }
56
57
        $extension = $this->newInstance();
58
59
        $extension->namespace = $namespace;
60
61
        $extension->save();
62
63
        return $extension;
64
    }
65
66
    /**
67
     * Find a extension by it's namespace.
68
     *
69
     * @param  $namespace
70
     * @return mixed
71
     */
72
    public function findByNamespace($namespace)
73
    {
74
        return $this->where('namespace', $namespace)->first();
75
    }
76
77
    /**
78
     * Get all enabled extension namespaces.
79
     *
80
     * @return EloquentCollection
81
     */
82
    public function getEnabledNamespaces()
83
    {
84
        return $this->where('enabled', true)->get()->pluck('namespace');
85
    }
86
87
    /**
88
     * Get all installed extension namespaces.
89
     *
90
     * @return EloquentCollection
91
     */
92
    public function getInstalledNamespaces()
93
    {
94
        return $this->where('installed', true)->get()->pluck('namespace');
95
    }
96
97
    /**
98
     * Return a new collection.
99
     *
100
     * @param  array $items
101
     * @return EloquentCollection
102
     */
103
    public function newCollection(array $items = [])
104
    {
105
        return new EloquentCollection($items);
106
    }
107
}
108

src/Addon/Module/ModuleModel.php 1 location

@@ 15-107 (lines=93) @@
12
 * @author PyroCMS, Inc. <[email protected]>
13
 * @author Ryan Thompson <[email protected]>
14
 */
15
class ModuleModel extends EloquentModel implements ModuleInterface
16
{
17
18
    /**
19
     * Define the table name.
20
     *
21
     * @var string
22
     */
23
    protected $table = 'addons_modules';
24
25
    /**
26
     * Disable timestamps for modules.
27
     *
28
     * @var bool
29
     */
30
    public $timestamps = false;
31
32
    /**
33
     * Boot the model
34
     */
35
    protected static function boot()
36
    {
37
        self::observe(app(EloquentObserver::class));
38
39
        parent::boot();
40
    }
41
42
    /**
43
     * Find a module by it's namespace or return a new
44
     * module with the given namespace.
45
     *
46
     * @param  $namespace
47
     * @return ModuleModel
48
     */
49
    public function findByNamespaceOrNew($namespace)
50
    {
51
        $module = $this->findByNamespace($namespace);
52
53
        if ($module instanceof ModuleModel) {
54
            return $module;
55
        }
56
57
        $module = $this->newInstance();
58
59
        $module->namespace = $namespace;
60
61
        $module->save();
62
63
        return $module;
64
    }
65
66
    /**
67
     * Find a module by it's namespace.
68
     *
69
     * @param  $namespace
70
     * @return null|ModuleModel
71
     */
72
    public function findByNamespace($namespace)
73
    {
74
        return $this->where('namespace', $namespace)->first();
75
    }
76
77
    /**
78
     * Get all enabled module namespaces.
79
     *
80
     * @return EloquentCollection
81
     */
82
    public function getEnabledNamespaces()
83
    {
84
        return $this->where('installed', true)->where('enabled', true)->get()->pluck('namespace');
85
    }
86
87
    /**
88
     * Get all installed module namespaces.
89
     *
90
     * @return EloquentCollection
91
     */
92
    public function getInstalledNamespaces()
93
    {
94
        return $this->where('installed', true)->get()->pluck('namespace');
95
    }
96
97
    /**
98
     * Return a new collection.
99
     *
100
     * @param  array $items
101
     * @return EloquentCollection
102
     */
103
    public function newCollection(array $items = [])
104
    {
105
        return new EloquentCollection($items);
106
    }
107
}
108