1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
declare(strict_types=1);
21

22
abstract class PHPStanCommandBuilder
23
{
24
    private const ARG_HELP = '--help';
25
    private const ARG_QUIET = '--quiet';
26
    private const ARG_VERSION = '--version';
27
    private const ARG_ANSI = '--ansi';
28
    private const ARG_NO_ANSI = '--no-ansi';
29
    private const ARG_NO_INTERACTION = '--no-interaction';
30
    private const ARG_VERBOSE = '--verbose';
31

32 1
    public function build(PHPStanTask $task): void
33
    {
34 1
        $this->validate($task);
35

36 1
        $cmd = $task->getCommandline();
37 1
        $cmd->setExecutable($task->getExecutable());
38 1
        $cmd->createArgument()->setValue($task->getCommand());
39 1
        if ($task->isHelp()) {
40 1
            $cmd->createArgument()->setValue(self::ARG_HELP);
41
        }
42 1
        if ($task->isQuiet()) {
43 1
            $cmd->createArgument()->setValue(self::ARG_QUIET);
44
        }
45 1
        if ($task->isVersion()) {
46 1
            $cmd->createArgument()->setValue(self::ARG_VERSION);
47
        }
48 1
        if ($task->isAnsi()) {
49 1
            $cmd->createArgument()->setValue(self::ARG_ANSI);
50
        }
51 1
        if ($task->isNoAnsi()) {
52 1
            $cmd->createArgument()->setValue(self::ARG_NO_ANSI);
53
        }
54 1
        if ($task->isNoInteraction()) {
55 1
            $cmd->createArgument()->setValue(self::ARG_NO_INTERACTION);
56
        }
57 1
        if ($task->isVerbose()) {
58 1
            $cmd->createArgument()->setValue(self::ARG_VERBOSE);
59
        }
60
    }
61

62 1
    private function validate(PHPStanTask $task): void
63
    {
64 1
        if (empty($task->getExecutable())) {
65 1
            throw new BuildException('executable not set');
66
        }
67
    }
68
}

Read our documentation on viewing source code .

Loading