Completed
Push — master ( 6b77c2...0b4fa8 )
by Andrii
04:43
created

PagesList   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 50
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFromDir() 0 16 4
A getDataProvider() 0 9 1
1
<?php
2
/**
3
 * Yii2 Pages Module
4
 *
5
 * @link      https://github.com/hiqdev/yii2-module-pages
6
 * @package   yii2-module-pages
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\modules\pages\models;
12
13
use hiqdev\yii2\modules\pages\storage\FileSystemStorage;
14
use yii\data\ArrayDataProvider;
15
use yii\helpers\ArrayHelper;
16
17
class PagesList
18
{
19
    /** @var AbstractPage[]  */
20
    protected $pages = [];
21
22
    /**
23
     * PagesList constructor.
24
     * @param AbstractPage[] $pages
25
     */
26
    public function __construct(array $pages)
27
    {
28
        $this->pages = $pages;
29
    }
30
31
    /**
32
     * @param string $path
33
     * @param FileSystemStorage $storage
34
     * @return PagesList
35
     * @throws \yii\base\InvalidConfigException
36
     */
37
    public static function createFromDir(string $path, FileSystemStorage $storage): PagesList
38
    {
39
        $list = $storage->getFileSystem()->listContents($path);
40
        ArrayHelper::multisort($list, 'basename', SORT_DESC);
41
42
        $pages = [];
43
        foreach ($list as $file) {
44
            if ($file['type'] !== 'file' || $file['basename'][0] === '.') {
45
                continue;
46
            }
47
            $pages[] = AbstractPage::createFromFile($file['path'], $storage);
48
        }
49
        $index = new static($pages, $storage);
0 ignored issues
show
Unused Code introduced by
The call to PagesList::__construct() has too many arguments starting with $storage.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
50
51
        return $index;
52
    }
53
54
    /**
55
     * @return ArrayDataProvider
56
     */
57
    public function getDataProvider(): ArrayDataProvider
58
    {
59
        return new ArrayDataProvider([
60
            'allModels' => $this->pages,
61
            'pagination' => [
62
                'pageSize' => 5,
63
            ]
64
        ]);
65
    }
66
}
67