GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b5125b...c08d10 )
by Shea
06:09
created

LocalRepository::getProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Caffeinated\Modules\Repositories;
3
4
use Caffeinated\Modules\Repositories\Repository;
5
6
class LocalRepository extends Repository
7
{
8
	/**
9
	 * Update cached repository of module information.
10
	 *
11
	 * @return bool
12
	 */
13
	public function optimize()
14
	{
15
		$cachePath = $this->getCachePath();
16
        $cache     = $this->getCache();
17
        $basenames = $this->getAllBasenames();
18
		$modules   = collect();
19
20
		$basenames->each(function($module, $key) use ($modules, $cache) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
			$temp     = collect($cache->get($module));
22
			$manifest = collect($this->getManifest($module));
23
24
			$modules->put($module, $temp->merge($manifest));
25
		});
26
27
		$modules->each(function($module) {
28
			if (! $module->has('enabled')) {
29
				$module->put('enabled', true);
30
			}
31
32
			if (! $module->has('order')) {
33
				$module->put('order', 9001);
34
			}
35
36
			return $module;
37
		});
38
39
        $content = json_encode($modules->all(), JSON_PRETTY_PRINT);
40
41
        return $this->files->put($cachePath, $content);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->files->put($cachePath, $content); (integer) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...toryInterface::optimize of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
42
	}
43
44
	/**
45
	* Get all modules.
46
	*
47
	* @return Collection
48
	*/
49
	public function all()
50
	{
51
		return $this->getCache()->sortBy('order');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getCache()->sortBy('order'); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...epositoryInterface::all of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
52
	}
53
54
	/**
55
	* Get all module slugs.
56
	*
57
	* @return Collection
58
	*/
59
	public function slugs()
60
	{
61
		$slugs = collect();
62
63
		$this->all()->each(function($item, $key) use ($slugs) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
			$slugs->push($item['slug']);
65
		});
66
67
		return $slugs;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $slugs; (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...ositoryInterface::slugs of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
68
	}
69
70
	/**
71
	 * Get modules based on where clause.
72
	 *
73
	 * @param  string  $key
74
	 * @param  mixed   $value
75
	 * @return Collection
76
	 */
77
	public function where($key, $value)
78
	{
79
		return $this->all()->where($key, $value);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->all()->where($key, $value); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...ositoryInterface::where of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
80
	}
81
82
	/**
83
	 * Sort modules by given key in ascending order.
84
	 *
85
	 * @param  string  $key
86
	 * @return Collection
87
	 */
88
	public function sortBy($key)
89
	{
90
		$collection = $this->all();
91
92
		return $collection->sortBy($key);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $collection->sortBy($key); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...sitoryInterface::sortBy of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
93
	}
94
95
	/**
96
	* Sort modules by given key in ascending order.
97
	*
98
	* @param  string  $key
99
	* @return Collection
100
	*/
101
	public function sortByDesc($key)
102
	{
103
		$collection = $this->all();
104
105
		return $collection->sortByDesc($key);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $collection->sortByDesc($key); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...ryInterface::sortByDesc of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
106
	}
107
108
	/**
109
	 * Determines if the given module exists.
110
	 *
111
	 * @param  string  $slug
112
	 * @return bool
113
	 */
114
	public function exists($slug)
115
	{
116
		return $this->slugs()->contains(strtolower($slug));
117
	}
118
119
	/**
120
	 * Returns count of all modules.
121
	 *
122
	 * @return int
123
	 */
124
	public function count()
125
	{
126
		return $this->all()->count();
127
	}
128
129
	/**
130
	 * Get a module property value.
131
	 *
132
	 * @param  string $property
133
	 * @param  mixed  $default
134
	 * @return mixed
135
	 */
136
	public function get($property, $default = null)
137
	{
138
		list($slug, $key) = explode('::', $property);
139
140
		$module = $this->where('slug', $slug);
141
142
		return $module->get($key, $default);
143
	}
144
145
	/**
146
	* Set the given module property value.
147
	*
148
	* @param  string  $property
149
	* @param  mixed   $value
150
	* @return bool
151
	*/
152
	public function set($property, $value)
153
	{
154
		list($slug, $key) = explode('::', $property);
155
156
		$cachePath = $this->getCachePath();
157
		$cache     = $this->getCache();
158
		$module    = $this->where('slug', $slug);
159
		$moduleKey = $module->keys()->first();
160
		$values    = $module->first();
161
162
		if (isset($values[$key])) {
163
			unset($values[$key]);
164
		}
165
166
		$values[$key] = $value;
167
168
		$module = collect([$moduleKey => $values]);
169
170
        $merged  = $cache->merge($module);
171
        $content = json_encode($merged->all(), JSON_PRETTY_PRINT);
172
173
        return $this->files->put($cachePath, $content);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->files->put($cachePath, $content); (integer) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...epositoryInterface::set of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
174
	}
175
176
	/**
177
	 * Get all enabled modules.
178
	 *
179
	 * @return Collection
180
	 */
181
	public function enabled()
182
	{
183
		return $this->all()->where('enabled', true);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->all()->where('enabled', true); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...itoryInterface::enabled of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
184
	}
185
186
	/**
187
	 * Get all disabled modules.
188
	 *
189
	 * @return Collection
190
	 */
191
	public function disabled()
192
	{
193
        return $this->all()->where('enabled', false);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->all()->where('enabled', false); (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...toryInterface::disabled of type Caffeinated\Modules\Contracts\Collection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
194
	}
195
196
	/**
197
	 * Check if specified module is enabled.
198
	 *
199
	 * @param  string $slug
200
	 * @return bool
201
	 */
202
	public function isEnabled($slug)
203
	{
204
		$module = $this->where('slug', $slug)
205
			->first();
206
207
		return ($module['enabled'] === true);
208
	}
209
210
	/**
211
	 * Check if specified module is disabled.
212
	 *
213
	 * @param  string $slug
214
	 * @return bool
215
	 */
216
	public function isDisabled($slug)
217
	{
218
		$module = $this->where('slug', $slug)
219
			->first();
220
221
		return ($module['enabled'] === false);
222
	}
223
224
	/**
225
	 * Enables the specified module.
226
	 *
227
	 * @param  string $slug
228
	 * @return bool
229
	 */
230
	public function enable($slug)
231
	{
232
        return $this->set($slug.'::enabled', true);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->set($slug . '::enabled', true); (integer) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...sitoryInterface::enable of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
233
	}
234
235
	/**
236
	 * Disables the specified module.
237
	 *
238
	 * @param  string $slug
239
	 * @return bool
240
	 */
241
	public function disable($slug)
242
	{
243
        return $this->set($slug.'::enabled', false);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->set($slug . '::enabled', false); (integer) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...itoryInterface::disable of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
244
	}
245
246
    /**
247
     * Get the contents of the cache file.
248
     *
249
     * The cache file lists all module slugs and their
250
     * enabled or disabled status. This can be used to
251
     * filter out modules depending on their status.
252
     *
253
     * @return Collection
254
     */
255
    public function getCache()
256
    {
257
		$cachePath = $this->getCachePath();
258
259
        if (! $this->files->exists($cachePath)) {
260
            $content = json_encode(array(), JSON_PRETTY_PRINT);
261
262
            $this->files->put($cachePath, $content);
263
264
            return collect(json_decode($content, true));
265
        }
266
267
        return collect(json_decode($this->files->get($cachePath), true));
268
    }
269
270
	/**
271
	 * Get the path to the cache file.
272
	 *
273
	 * @return string
274
	 */
275
	protected function getCachePath()
276
	{
277
		return storage_path('app/modules.json');
278
	}
279
}
280