Passed
Branch master (613786)
by Hannes
02:27
created

FileDumpingListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onFileEvent() 0 3 1
A onChangesDiscarded() 0 3 1
A onChangesCommitted() 0 10 2
1
<?php
2
/**
3
 * This file is part of byrokrat\giroapp.
4
 *
5
 * byrokrat\giroapp is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\giroapp is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016-20 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\giroapp\Event\Listener;
24
25
use byrokrat\giroapp\DependencyInjection\DispatcherProperty;
26
use byrokrat\giroapp\Event\ChangesCommitted;
27
use byrokrat\giroapp\Event\ChangesDiscarded;
28
use byrokrat\giroapp\Event\FileEvent;
29
use byrokrat\giroapp\Event\DebugEvent;
30
use byrokrat\giroapp\Filesystem\FileInterface;
31
use byrokrat\giroapp\Filesystem\FilesystemInterface;
32
use byrokrat\giroapp\Filesystem\FileProcessorInterface;
33
34
final class FileDumpingListener
35
{
36
    use DispatcherProperty;
37
38
    /**
39
     * @var FilesystemInterface
40
     */
41
    private $filesystem;
42
43
    /**
44
     * @var FileProcessorInterface
45
     */
46
    private $fileProcessor;
47
48
    /**
49
     * @var FileInterface[]
50
     */
51
    private $files = [];
52
53
    public function __construct(FilesystemInterface $filesystem, FileProcessorInterface $fileProcessor)
54
    {
55
        $this->filesystem = $filesystem;
56
        $this->fileProcessor = $fileProcessor;
57
    }
58
59
    public function onFileEvent(FileEvent $event): void
60
    {
61
        $this->files[] = $event->getFile();
62
    }
63
64
    public function onChangesCommitted(ChangesCommitted $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
    public function onChangesCommitted(/** @scrutinizer ignore-unused */ ChangesCommitted $event): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        foreach ($this->files as $file) {
67
            $file = $this->fileProcessor->processFile($file);
68
69
            $this->dispatcher->dispatch(
70
                new DebugEvent("Dumping file '{$file->getFilename()}'")
71
            );
72
73
            $this->filesystem->writeFile($file);
74
        }
75
    }
76
77
    public function onChangesDiscarded(ChangesDiscarded $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

77
    public function onChangesDiscarded(/** @scrutinizer ignore-unused */ ChangesDiscarded $event): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        $this->files = [];
80
    }
81
}
82