Completed
Pull Request — master (#221)
by Thomas
28:24 queued 26:59
created

ReaderFactory::factory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the browscap-php package.
4
 *
5
 * Copyright (c) 1998-2017, Browser Capabilities Project
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
declare(strict_types = 1);
12
namespace BrowscapPHP\Util\Logfile;
13
14
/**
15
 * abstract parent class for all readers
16
 */
17
final class ReaderFactory
18
{
19
    /**
20
     * @var ReaderInterface[]
21
     */
22
    private static $readers = [];
23
24
    /**
25
     * @return \BrowscapPHP\Util\Logfile\ReaderCollection
26
     */
27 1
    public static function factory() : ReaderCollection
28
    {
29 1
        $collection = new ReaderCollection();
30
31 1
        foreach (self::getReaders() as $reader) {
32 1
            $collection->addReader($reader);
33
        }
34
35 1
        return $collection;
36
    }
37
38
    /**
39
     * @return \BrowscapPHP\Util\Logfile\ReaderInterface[]
40
     */
41 1
    private static function getReaders() : array
42
    {
43 1
        if (self::$readers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$readers of type BrowscapPHP\Util\Logfile\ReaderInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
44
            return self::$readers;
45
        }
46
47 1
        self::$readers[] = new ApacheCommonLogFormatReader();
48
49 1
        return self::$readers;
50
    }
51
}
52