Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.43% covered (warning)
71.43%
5 / 7
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
BoxedExecutor
71.43% covered (warning)
71.43%
5 / 7
50.00% covered (danger)
50.00%
2 / 4
5.58
0.00% covered (danger)
0.00%
0 / 1
 execute
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 executeValid
n/a
0 / 0
n/a
0 / 0
0
 createCommand
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setValidationConfig
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 assertIsValid
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 areUrlFilesAllowed
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3namespace Shellbox\Command;
4
5/**
6 * Base class for things that execute BoxedCommands
7 */
8abstract class BoxedExecutor {
9    /** @var Validator|null */
10    protected $validator;
11
12    /**
13     * Execute a boxed command.
14     *
15     * @param BoxedCommand $command
16     * @return BoxedResult
17     */
18    final public function execute( BoxedCommand $command ) {
19        $this->assertIsValid( $command );
20        return $this->executeValid( $command );
21    }
22
23    /**
24     * Execute a BoxedCommand that has already been validated.
25     *
26     * @param BoxedCommand $command
27     * @return BoxedResult
28     */
29    abstract public function executeValid( BoxedCommand $command );
30
31    /**
32     * Create an empty command linked to this executor
33     *
34     * @return BoxedCommand
35     */
36    public function createCommand() {
37        return new BoxedCommand( $this );
38    }
39
40    /**
41     * Set validation configuration
42     *
43     * @param array $config
44     */
45    public function setValidationConfig( $config ) {
46        $this->validator = new Validator( $config );
47    }
48
49    /**
50     * Validate the command. If it is not valid, throw an exception
51     *
52     * @param BoxedCommand $command
53     * @throws ValidationError
54     */
55    protected function assertIsValid( BoxedCommand $command ) {
56        if ( !$this->validator ) {
57            return;
58        }
59        $this->validator->validate( $command );
60    }
61
62    /**
63     * Whether the executor can download input files and upload output files
64     * specified with BoxedCommand::inputFileFromUrl and the like.
65     *
66     * @since 4.1.0
67     * @return bool
68     */
69    abstract public function areUrlFilesAllowed();
70}