Completed
Push — master ( 519f76...318dd5 )
by Raffael
24:13 queued 15:29
created

AbstractFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 60
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A flush() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * tubee
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
     * Writable stream (destination endpoint).
44
     *
45
     * @var resource
46
     */
47
    protected $writable;
48
49
    /**
50
     * Init endpoint.
51
     */
52 21
    public function __construct(string $name, string $type, string $file, StorageInterface $storage, CollectionInterface $collection, WorkflowFactory $workflow, LoggerInterface $logger, ?Iterable $resource = [])
53
    {
54 21
        $this->storage = $storage;
55 21
        $this->file = $file;
56 21
        parent::__construct($name, $type, $collection, $workflow, $logger, $resource);
57 21
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 5
    public function flush(bool $simulate = false): bool
63
    {
64 5
        $this->logger->info('flush file ['.$this->file.'] from endpoint ['.$this->name.']', [
65 5
            'category' => get_class($this),
66
        ]);
67
68 5
        if ($simulate === true) {
69
            return true;
70
        }
71
72 5
        if (ftruncate($this->writable, 0) === false) {
73 1
            throw new Exception\WriteOperationFailed('failed flush file '.$this->file);
74
        }
75
76 4
        return true;
77
    }
78
}
79