FileInterface   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 50
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasHeader() 0 3 1
A getContent() 0 3 1
A setHeader() 0 9 3
A getHeader() 0 6 2
A isContentIterator() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Infrastructure Related Agent
5
 * @author Max Demian <[email protected]>
6
 */
7
8
namespace Ticaje\FileManager\Infrastructure\Driver\Traits;
9
10
use Iterator;
11
use Ticaje\FileManager\Infrastructure\Driver\Reader\Interfaces\FileInterface as ReferencedSignature;
12
13
/**
14
 * Trait FileInterface
15
 * @package Ticaje\FileManager\Infrastructure\Driver\Traits
16
 * Classes using this trait must implement interface FileInterface
17
 */
18
trait FileInterface
19
{
20
    /** @var Iterator|array $header */
21
    private $header = [];
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function getHeader()
27
    {
28
        return !empty($this->header) ? $this->header : (function () {
29
            $this->setHeader();
30
31
            return $this->header;
32
        })();
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    private function setHeader(): ReferencedSignature
39
    {
40
        if ($this->hasHeader()) {
41
            $this->header = $this->isContentIterator() ? (function () {
42
                return $this->content->current();
43
            })() : array_shift($this->getContent());
0 ignored issues
show
Bug introduced by
$this->getContent() of type Iterator is incompatible with the type array expected by parameter $array of array_shift(). ( Ignorable by Annotation )

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

43
            })() : array_shift(/** @scrutinizer ignore-type */ $this->getContent());
Loading history...
44
        }
45
46
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ticaje\FileManager\Infra...er\Traits\FileInterface which is incompatible with the type-hinted return Ticaje\FileManager\Infra...nterfaces\FileInterface.
Loading history...
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function hasHeader(): bool
53
    {
54
        return $this->hasHeader;
55
    }
56
57
    private function isContentIterator()
58
    {
59
        return $this->content instanceof Iterator;
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65
    public function getContent(): Iterator
66
    {
67
        return $this->content;
68
    }
69
}
70