Completed
Push — collection-and-generator ( 3521a6 )
by Arnaud
02:42
created

AbstractGenerator::runGenerate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 2
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Generator;
10
11
use Cecil\Collection\Page\Collection as PagesCollection;
12
use Cecil\Config;
13
use Cecil\Util;
14
15
/**
16
 * Abstract class AbstractGenerator.
17
 */
18
abstract class AbstractGenerator implements GeneratorInterface
19
{
20
    /* @var Config */
21
    protected $config;
22
    /* @var PagesCollection */
23
    protected $pagesCollection;
24
    /* @var $messageCallback */
25
    protected $messageCallback;
26
    /* @var PagesCollection */
27
    protected $generatedPages;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function __construct(Config $config)
33
    {
34
        $this->config = $config;
35
        // Create new empty collection
36
        //$this->generatedPages = new PagesCollection('generator-'.$this->getGeneratorName($this));
37
        $this->generatedPages = new PagesCollection('generator-'.Util::formatClassName($this));
0 ignored issues
show
Documentation introduced by
$this is of type this<Cecil\Generator\AbstractGenerator>, but the function expects a object<object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
40
    /**
41
     * @param PagesCollection $pagesCollection
42
     * @param \Closure        $messageCallback
43
     *
44
     * @return PagesCollection
45
     */
46
    public function runGenerate(PagesCollection $pagesCollection, \Closure $messageCallback): PagesCollection
47
    {
48
        $this->pagesCollection = $pagesCollection;
49
        $this->messageCallback = $messageCallback;
50
51
        $this->generate();
52
53
        return $this->generatedPages;
54
    }
55
56
    /**
57
     * Format generator name.
58
     *
59
     * @param self $class
0 ignored issues
show
Documentation introduced by
Should the type for parameter $class not be \self?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
60
     *
61
     * @return string
62
     */
63
    protected static function getGeneratorName(self $class): string
64
    {
65
        return strtolower(substr(strrchr(get_class($class), '\\'), 1));
66
    }
67
}
68