Passed
Push — master ( 3896ee...e50616 )
by Raffael
05:45
created

AbstractFile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * tubee.io
7
 *
8
 * @copyright   Copryright (c) 2017-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Tubee\Endpoint;
13
14
use Psr\Log\LoggerInterface;
15
use Tubee\Collection\CollectionInterface;
16
use Tubee\Storage\StorageInterface;
17
use Tubee\Workflow\Factory as WorkflowFactory;
18
19
abstract class AbstractFile extends AbstractEndpoint
20
{
21
    /**
22
     * File.
23
     *
24
     * @var string
25
     */
26
    protected $file;
27
28
    /**
29
     * Storage.
30
     *
31
     * @var StorageInterface
32
     */
33
    protected $storage;
34
35
    /**
36
     * Files.
37
     *
38
     * @var array
39
     */
40
    protected $files = [];
41
42
    /**
43
     * Init endpoint.
44
     */
45 24
    public function __construct(string $name, string $type, string $file, StorageInterface $storage, CollectionInterface $collection, WorkflowFactory $workflow, LoggerInterface $logger, ?Iterable $resource = [])
46
    {
47 24
        $this->storage = $storage;
48 24
        $this->file = $file;
49 24
        parent::__construct($name, $type, $collection, $workflow, $logger, $resource);
50 24
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 8
    public function flush(bool $simulate = false): bool
56
    {
57 8
        $this->logger->info('flush file ['.$this->file.'] from endpoint ['.$this->name.']', [
58 8
            'category' => get_class($this),
59
        ]);
60
61 8
        if ($simulate === true) {
62
            return true;
63
        }
64
65 8
        foreach ($this->files as $stream) {
66 8
            if (ftruncate($stream['stream'], 0) === false) {
67 8
                throw new Exception\WriteOperationFailed('failed flush file '.$this->file);
68
            }
69
        }
70
71 7
        return true;
72
    }
73
}
74