StatTrait::populateFromLetter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters\Models\Stats;
4
5
use ByTIC\DocumentGenerator\PdfLetters\Models\PdfLetters\PdfLetterTrait;
6
use Nip\Records\Record;
7
use Nip\Records\Traits\AbstractTrait\RecordTrait as AbstractRecordTrait;
8
9
/**
10
 * Class StatTrait
11
 * @package ByTIC\DocumentGenerator\PdfLetters\Models\Stats
12
 *
13
 * @property int $id_letter
14
 * @property string $stat_type
15
 * @property int $stat_id
16
 * @property int $value
17
 */
18
trait StatTrait
19
{
20
    use AbstractRecordTrait;
21
22
    /**
23
     * @param Record|PdfLetterTrait $letter
24
     */
25
    public function populateFromLetter($letter)
26
    {
27
        $this->id_letter = $letter->getPrimaryKey();
0 ignored issues
show
Bug introduced by
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        /** @scrutinizer ignore-call */ 
28
        $this->id_letter = $letter->getPrimaryKey();
Loading history...
Documentation Bug introduced by
It seems like $letter->getPrimaryKey() can also be of type array or array. However, the property $id_letter is declared as type integer. 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...
28
    }
29
30
    /**
31
     * @param $related
32
     */
33
    public function populateFromRelated(\Nip\Records\AbstractModels\Record $related)
34
    {
35
        $this->stat_type = $related->getManager()->getController();
36
        $this->stat_id = $related->getPrimaryKey();
37
    }
38
}
39