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.

StringBased   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 43
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContents() 0 4 1
A setContents() 0 6 1
1
<?php
2
namespace Naneau\FileGen\File\Contents;
3
4
use Naneau\FileGen\File\Contents;
5
6
/**
7
 * String based file contents
8
 */
9
class StringBased implements Contents
10
{
11
    /**
12
     * Contents of the file
13
     *
14
     * @var string
15
     **/
16
    private $contents;
17
18
    /**
19
     * Constructor
20
     *
21
     * @param string $contents
22
     * @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...
23
     **/
24
    public function __construct($contents)
25
    {
26
        $this->setContents($contents);
27
    }
28
29
    /**
30
     * Get the contents of the file
31
     *
32
     * @return string
33
     */
34
    public function getContents()
35
    {
36
        return $this->contents;
37
    }
38
39
    /**
40
     * Set the contents of the file
41
     *
42
     * @param  ContentGenerator|string $contents
43
     * @return self
44
     */
45
    public function setContents($contents)
46
    {
47
        $this->contents = $contents;
0 ignored issues
show
Documentation Bug introduced by
It seems like $contents can also be of type object<Naneau\FileGen\Fi...tents\ContentGenerator>. However, the property $contents is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
48
49
        return $this;
50
    }
51
}
52