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

Repository::getManifest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
namespace Caffeinated\Modules\Repositories;
3
4
use Caffeinated\Modules\Contracts\RepositoryInterface;
5
use Illuminate\Config\Repository as Config;
6
use Illuminate\Filesystem\Filesystem;
7
8
abstract class Repository implements RepositoryInterface
9
{
10
    /**
11
     * @var \Illuminate\Config\Repository
12
     */
13
    protected $config;
14
15
    /**
16
     * @var \Illuminate\Filesystem\Filesystem
17
     */
18
    protected $files;
19
20
    /**
21
     * @var string $path Path to the defined modules directory
22
     */
23
    protected $path;
24
25
    /**
26
     * Constructor method.
27
     *
28
     * @param \Illuminate\Config\Repository      $config
29
     * @param \Illuminate\Filesystem\Filesystem  $files
30
     */
31
    public function __construct(Config $config, Filesystem $files)
32
    {
33
        $this->config = $config;
34
        $this->files  = $files;
35
    }
36
37
    /**
38
	 * Get all module basenames
39
	 *
40
	 * @return array
41
	 */
42
	protected function getAllBasenames()
43
	{
44
		$path = $this->getPath();
45
46
        try {
47
            $collection = collect($this->files->directories($path));
48
49
            $basenames  = $collection->map(function($item, $key) {
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...
50
                return basename($item);
51
            });
52
53
    		return $basenames;
54
        } catch (\InvalidArgumentException $e) {
55
            return collect(array());
56
        }
57
	}
58
59
    /**
60
	 * Get a module's manifest contents.
61
	 *
62
	 * @param  string $slug
63
	 * @return Collection|null
64
	 */
65
	public function getManifest($slug)
66
	{
67
		if (! is_null($slug)) {
68
			$module     = studly_case($slug);
69
			$path       = $this->getManifestPath($module);
70
			$contents   = $this->files->get($path);
71
			$collection = collect(json_decode($contents, true));
72
73
			return $collection;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $collection; (Illuminate\Support\Collection) is incompatible with the return type declared by the interface Caffeinated\Modules\Cont...yInterface::getManifest 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...
74
		}
75
76
		return null;
77
	}
78
79
    /**
80
	 * Get modules path.
81
	 *
82
	 * @return string
83
	 */
84
	public function getPath()
85
	{
86
		return $this->path ?: $this->config->get('modules.path');
87
	}
88
89
    /**
90
	 * Set modules path in "RunTime" mode.
91
	 *
92
	 * @param  string $path
93
	 * @return object $this
94
	 */
95
	public function setPath($path)
96
	{
97
		$this->path = $path;
98
99
		return $this;
100
	}
101
102
    /**
103
	 * Get path for the specified module.
104
	 *
105
	 * @param  string $slug
106
	 * @return string
107
	 */
108
	public function getModulePath($slug)
109
	{
110
		$module = studly_case($slug);
111
112
		return $this->getPath()."/{$module}/";
113
	}
114
115
    /**
116
     * Get path of module manifest file.
117
     *
118
     * @param  string $module
0 ignored issues
show
Bug introduced by
There is no parameter named $module. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
119
     * @return string
120
     */
121
    protected function getManifestPath($slug)
122
    {
123
        return $this->getModulePath($slug).'module.json';
124
    }
125
126
    /**
127
     * Get modules namespace.
128
     *
129
     * @return string
130
     */
131
    public function getNamespace()
132
    {
133
        return rtrim($this->config->get('modules.namespace'), '/\\');
134
    }
135
}
136