parseRequestPdfLetterField()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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();
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
}
77