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.

File   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getContents() 0 13 2
A getContentGenerator() 0 4 1
A setContentGenerator() 0 14 3
1
<?php
2
namespace Naneau\FileGen;
3
4
use Naneau\FileGen\Parameterized;
5
6
use Naneau\FileGen\AccessRights;
7
8
use Naneau\FileGen\File\Contents as ContentGenerator;
9
use Naneau\FileGen\File\Contents\StringBased as StringContents;
10
11
use \InvalidArgumentException;
12
13
/**
14
 * A file
15
 */
16
class File extends AccessRights
17
{
18
    /**
19
     * Contents of the file
20
     *
21
     * @var ContentGenerator
22
     **/
23
    private $contentGenerator;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param  string                  $name
29
     * @param  ContentGenerator|string $contents
30
     * @param  int                     $mode     mode in octal 0XXX
31
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
32
     **/
33
    public function __construct($name, $contents = '', $mode = null)
34
    {
35
        parent::__construct($name, $mode);
36
37
        $this->setContentGenerator($contents);
0 ignored issues
show
Bug introduced by
It seems like $contents defined by parameter $contents on line 33 can also be of type string; however, Naneau\FileGen\File::setContentGenerator() does only seem to accept object<Naneau\FileGen\File\Contents>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38
    }
39
40
    /**
41
     * Get the contents as a string
42
     *
43
     * @param  array[string]string $parameters
0 ignored issues
show
Documentation introduced by
The doc-type array[string]string could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
44
     * @return string
45
     **/
46
    public function getContents(array $parameters = array())
47
    {
48
        // Merge incoming parameters with that of the content generator if the
49
        // content generator is parameterized
50
        if ($this->getContentGenerator() instanceof Parameterized) {
51
            $this->getContentGenerator()->setParameters(array_merge(
52
                $this->getContentGenerator()->getParameters(),
53
                $parameters
54
            ));
55
        }
56
57
        return $this->getContentGenerator()->getContents();
58
    }
59
60
    /**
61
     * Get the content generator
62
     *
63
     * @return ContentGenerator
64
     */
65
    public function getContentGenerator()
66
    {
67
        return $this->contentGenerator;
68
    }
69
70
    /**
71
     * Set the content generator
72
     *
73
     * @param  ContentGenerator $contentGenerator
74
     * @return File
75
     */
76
    public function setContentGenerator($contentGenerator)
77
    {
78
        if (is_string($contentGenerator)) {
79
            $this->contentGenerator = new StringContents($contentGenerator);
80
        } elseif ($contentGenerator instanceof ContentGenerator) {
81
            $this->contentGenerator = $contentGenerator;
82
        } else {
83
            throw new InvalidArgumentException(
84
                'Content generator needs to be string or instance of Naneau\FileGen\File\Contents'
85
            );
86
        }
87
88
        return $this;
89
    }
90
}
91