Passed
Push — master ( 4017d9...9757db )
by Dev
10:15
created

PageScannerController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A scanAction() 0 24 4
1
<?php
2
3
namespace PiedWeb\CMSBundle\Extension\PageScanner;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\DependencyInjection\Container;
7
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
8
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
9
10
class PageScannerController extends AbstractController
11
{
12
    /**
13
     * @var PageScannerService
14
     */
15
    protected $scanner;
16
17
    /**
18
     * @var Container
19
     */
20
    protected $container;
21
22
    /**
23
     * @var ContainerBag
24
     */
25
    protected $params;
26
27
    public function __construct(PageScannerService $scanner, ParameterBagInterface $params)
28
    {
29
        $this->scanner = $scanner;
30
        $this->params = $params;
0 ignored issues
show
Documentation Bug introduced by
$params is of type Symfony\Component\Depend...g\ParameterBagInterface, but the property $params was declared to be of type Symfony\Component\Depend...rameterBag\ContainerBag. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
31
    }
32
33
    public function scanAction()
34
    {
35
        $pages = $this->getDoctrine()
36
            ->getRepository($this->params->get('pwc.entity_page'))
37
            ->findAll();
38
39
        $errors = [];
40
        $errorNbr = 0;
41
42
        foreach ($pages as $page) {
43
            // todo import scanner via setScanner + services.yaml
44
            $scan = $this->scanner->scan($page);
45
            if (true !== $scan) {
46
                $errors[$page->getId()] = $scan;
47
                $errorNbr = $errorNbr + \count($errors[$page->getId()]);
48
            }
49
50
            if ($errorNbr > 100) {
51
                break;
52
            }
53
        }
54
55
        return $this->render('@pwcPageScanner/results.html.twig', [
56
            'errorsByPages' => $errors,
57
        ]);
58
    }
59
}
60