1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* (c) Anton Medvedev <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | |||
11 | namespace Deployer\Logger; |
||
12 | |||
13 | use Deployer\ProcessRunner\Printer; |
||
14 | use Deployer\Host\Host; |
||
15 | use Deployer\Logger\Handler\HandlerInterface; |
||
16 | |||
17 | class Logger |
||
18 | { |
||
19 | /** |
||
20 | * @var HandlerInterface |
||
21 | */ |
||
22 | 14 | private $handler; |
|
23 | |||
24 | 14 | public function __construct(HandlerInterface $handler) |
|
25 | 14 | { |
|
26 | $this->handler = $handler; |
||
27 | 9 | } |
|
28 | |||
29 | 9 | public function log(string $message): void |
|
30 | 9 | { |
|
31 | $this->handler->log("$message\n"); |
||
32 | } |
||
33 | |||
34 | public function callback(Host $host): \Closure |
||
35 | { |
||
36 | return function ($type, $buffer) use ($host) { |
||
37 | $this->printBuffer($host, $type, $buffer); |
||
38 | }; |
||
39 | 9 | } |
|
40 | |||
41 | 9 | public function printBuffer(Host $host, string $type, string $buffer): void |
|
42 | 9 | { |
|
43 | foreach (explode("\n", rtrim($buffer)) as $line) { |
||
44 | 9 | $this->writeln($host, $type, $line); |
|
45 | } |
||
46 | 9 | } |
|
47 | |||
48 | 9 | public function writeln(Host $host, string $type, string $line): void |
|
0 ignored issues
–
show
|
|||
49 | { |
||
50 | // Omit empty lines |
||
51 | 9 | if (empty($line)) { |
|
52 | return; |
||
53 | } |
||
54 | |||
55 | 9 | $this->log("[{$host->getAlias()}] $line"); |
|
56 | } |
||
57 | } |
||
58 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.