Completed
Push — master ( 146147...1776d4 )
by Neomerx
01:58
created

FileSeedRunner::getSeedsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Application\Data;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Commands\IoInterface;
20
use Limoncello\Contracts\FileSystem\FileSystemInterface;
21
use Psr\Container\ContainerInterface;
22
23
/**
24
 * @package Limoncello\Application
25
 */
26
class FileSeedRunner extends BaseSeedRunner
27
{
28
    /**
29
     * @var string
30
     */
31
    private $seedsPath;
32
33
    /**
34
     * @var string[]
35
     */
36
    private $seedClasses;
37
38
    /**
39
     * @param IoInterface   $inOut
40
     * @param string        $seedsPath
41
     * @param callable|null $seedInit
42
     * @param string        $seedsTable
43
     */
44 2
    public function __construct(
45
        IoInterface $inOut,
46
        string $seedsPath,
47
        callable $seedInit = null,
48
        string $seedsTable = BaseMigrationRunner::SEEDS_TABLE
49
    ) {
50 2
        $this->setSeedsPath($seedsPath);
51
52 2
        parent::__construct($inOut, $seedInit, $seedsTable);
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 1 View Code Duplication
    public function run(ContainerInterface $container): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        // read & remember seed classes...
61 1
        assert($container->has(FileSystemInterface::class) === true);
62
        /** @var FileSystemInterface $fileSystem */
63 1
        $fileSystem = $container->get(FileSystemInterface::class);
64
65 1
        $path = $this->getSeedsPath();
66 1
        assert($fileSystem->exists($path) === true);
67 1
        $this->getIO()->writeInfo("Seeds `$path` started." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
0 ignored issues
show
Unused Code introduced by
The call to IoInterface::writeInfo() has too many arguments starting with \Limoncello\Contracts\Co...face::VERBOSITY_VERBOSE.

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...
68
69 1
        $seedClasses = $fileSystem->requireFile($path);
70 1
        $this->setSeedClasses($seedClasses);
71
72
        // ... and run actual seeding
73 1
        parent::run($container);
74
    }
75
76
    /**
77
     * @param string[] $seedClasses
78
     *
79
     * @return self
80
     */
81 1
    private function setSeedClasses(array $seedClasses): self
82
    {
83 1
        $this->seedClasses = $seedClasses;
84
85 1
        return $this;
86
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91 1
    protected function getSeedClasses(): array
92
    {
93 1
        return $this->seedClasses;
94
    }
95
96
    /**
97
     * @return string
98
     */
99 1
    protected function getSeedsPath(): string
100
    {
101 1
        return $this->seedsPath;
102
    }
103
104
    /**
105
     * @param string $seedsPath
106
     *
107
     * @return self
108
     */
109 2
    protected function setSeedsPath(string $seedsPath): self
110
    {
111 2
        $this->seedsPath = $seedsPath;
112
113 2
        return $this;
114
    }
115
}
116