Issues (8)

src/HandlersProcessor.php (3 issues)

1
<?php
2
/**
3
 * This file is a part of "Axessors" library.
4
 *
5
 * @author <[email protected]>
6
 * @license GPL
7
 */
8
9
namespace NoOne4rever\Axessors;
10
11
/**
12
 * Class HandlersProcessor.
13
 * 
14
 * Processes Axessors handlers.
15
 * 
16
 * @package NoOne4rever\Axessors
17
 */
18
class HandlersProcessor extends TokenProcessor
19
{
20
    /**
21
     * Creates list of handlers from a string of handlers definition.
22
     *
23
     * @param string $handlers handlers
24
     * @return string[] handlers
25
     */
26 2
    private function makeHandlersList(string $handlers): array
27
    {
28 2
        if ($handlers === '') {
29 2
            return [];
30
        }
31 2
        $injProcessor = new InjectedStringSuit($handlers);
32 2
        $result = $injProcessor->addSlashes(',')->get();
33 2
        $result = preg_split('{(?<!\\\\),\s*}', $result);
34 2
        foreach ($result as &$handler) {
35 2
            $injProcessor = new InjectedStringSuit(stripcslashes($handler));
36 2
            $handler = $injProcessor->resolveClassNames($this->namespace)->processThis()->wrapWithClosure()->get();
37
        }
38 2
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result could return the type false which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
41
    /**
42
     * Creates list of handlers for input data.
43
     *
44
     * @return string[] handlers
45
     */
46 2
    public function processInputData(): array
47
    {
48 2
        return $this->makeHandlersList($this->input);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeHandlersList($this->input) returns an array which contains values of type array which are incompatible with the documented value type string.
Loading history...
49
    }
50
51
    /**
52
     * Creates list of handlers for output data.
53
     *
54
     * @return string[] handlers
55
     */
56 2
    public function processOutputData(): array
57
    {
58 2
        return $this->makeHandlersList($this->output);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeHandlersList($this->output) returns an array which contains values of type array which are incompatible with the documented value type string.
Loading history...
59
    }
60
}