Passed
Push — master ( 671b4b...06a963 )
by Gabriel
04:41
created

PdfLetterFieldsControllerTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
c 0
b 0
f 0
dl 0
loc 63
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addNewModel() 0 14 2
A parseRequestPdfLetterField() 0 13 2
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters\Controllers\Admin\Fields;
4
5
use ByTIC\DocumentGenerator\PdfLetters\Models\PdfLetters\PdfLetterTrait;
6
use Nip\Controllers\Traits\AbstractControllerTrait;
7
use Nip\Records\AbstractModels\Record;
8
9
/**
10
 * Trait PdfLetterFieldsControllerTrait
11
 * @package ByTIC\DocumentGenerator\PdfLetters
12
 */
13
trait PdfLetterFieldsControllerTrait
14
{
15
    use AbstractControllerTrait;
16
17
    /**
18
     * @var PdfLetterTrait
19
     */
20
    protected $pdfLetter;
21
22
    /**
23
     * @var Record
24
     */
25
    protected $parent;
26
27
    /**
28
     * @return PdfLetterTrait
29
     */
30
    public function addNewModel()
31
    {
32
        /** @var PdfLetterTrait $item */
33
        $item = $this->getModelManager()->getNew();
0 ignored issues
show
Bug introduced by
It seems like getModelManager() 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

33
        $item = $this->/** @scrutinizer ignore-call */ getModelManager()->getNew();
Loading history...
34
        if ($this->pdfLetter) {
35
            $item->populateFromLetter($this->pdfLetter);
0 ignored issues
show
Bug introduced by
It seems like populateFromLetter() 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

35
            $item->/** @scrutinizer ignore-call */ 
36
                   populateFromLetter($this->pdfLetter);
Loading history...
36
            $this->getView()->Breadcrumbs()->addItem(
37
                $this->getModelManager()->getLetterManager()->getLabel('add'),
38
                '#'
39
            );
40
            return $item;
41
        }
42
43
        return $this->forward('index', 'error');
0 ignored issues
show
Bug introduced by
It seems like forward() 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

43
        return $this->/** @scrutinizer ignore-call */ forward('index', 'error');
Loading history...
44
    }
45
46
    /**
47
     * Called before action
48
     */
49
    protected function parseRequestPdfLetterField()
50
    {
51
        if ($this->getRequest()->get('id_letter')) {
52
            $this->pdfLetter = $this->checkForeignModelFromRequest(
53
                $this->getModelManager()->getLetterManager()->getTable(),
54
                'id_letter'
0 ignored issues
show
Bug introduced by
'id_letter' of type string is incompatible with the type boolean expected by parameter $key of ByTIC\DocumentGenerator\...reignModelFromRequest(). ( Ignorable by Annotation )

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

54
                /** @scrutinizer ignore-type */ 'id_letter'
Loading history...
55
            );
56
        } else {
57
            $field = $this->getModelFromRequest();
58
            $this->pdfLetter = $field->getPdfLetter();
0 ignored issues
show
Documentation Bug introduced by
It seems like $field->getPdfLetter() can also be of type Nip\Helpers\AbstractHelper. However, the property $pdfLetter is declared as type ByTIC\DocumentGenerator\...fLetters\PdfLetterTrait. 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...
59
        }
60
61
        $this->parent = $this->pdfLetter->getItem();
0 ignored issues
show
Bug introduced by
The method getItem() does not exist on null. ( Ignorable by Annotation )

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

61
        /** @scrutinizer ignore-call */ 
62
        $this->parent = $this->pdfLetter->getItem();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getItem() does not exist on Nip\Helpers\AbstractHelper. It seems like you code against a sub-type of Nip\Helpers\AbstractHelper such as Nip_Helper_Url or Nip\Helpers\View\Stylesheets or Nip\Helpers\View\Strings or Nip\Helpers\View\Paginator or Nip\Helpers\View\Arrays or Nip\Helpers\View\Icontext or Nip\Helpers\View\Color or Nip\Helpers\View\Scripts or Nip\Helpers\View\Url. ( Ignorable by Annotation )

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

61
        /** @scrutinizer ignore-call */ 
62
        $this->parent = $this->pdfLetter->getItem();
Loading history...
62
    }
63
64
    /**
65
     * @param bool $key
66
     * @return FieldTrait|Record
0 ignored issues
show
Bug introduced by
The type ByTIC\DocumentGenerator\...Admin\Fields\FieldTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     */
68
    abstract protected function getModelFromRequest($key = false);
69
70
    /**
71
     * @param $name
72
     * @param bool $key
73
     * @return mixed
74
     */
75
    abstract protected function checkForeignModelFromRequest($name, $key = false);
76
}