CountryRepository::getLoader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace GeoBase\Countries;
4
5
use GeoBase\Countries\Country\CountryLoader;
6
use GeoBase\Countries\Country\CountryMapper;
7
8
class CountryRepository
9
{
10
    /**
11
     * @var CountryCollection
12
     */
13
    private static $collection;
14
15
    /**
16
     * @var CountryEntity[]
17
     */
18
    private static $items = [];
19
20
    /**
21
     * @var CountryMapper
22
     */
23
    private static $mapper;
24
25
    /**
26
     * @var CountryLoader
27
     */
28
    private static $loader;
29
30
    /**
31
     * @return CountryCollection
32
     */
33 2
    public static function findAll()
34
    {
35 2
        if (null === self::$collection) {
36 1
            self::$collection = self::getMapper()->mapArrayToCollection(self::getLoader()->loadAllCountries());
0 ignored issues
show
Documentation Bug introduced by
It seems like self::getMapper()->mapAr...()->loadAllCountries()) of type object<GeoBase\Countries...ntry\CountryCollection> is incompatible with the declared type object<GeoBase\Countries\CountryCollection> of property $collection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        }
38
39 2
        return self::$collection;
0 ignored issues
show
Bug Compatibility introduced by
The expression self::$collection; of type GeoBase\Countries\Countr...tries\CountryCollection adds the type GeoBase\Countries\Country\CountryCollection to the return on line 39 which is incompatible with the return type documented by GeoBase\Countries\CountryRepository::findAll of type GeoBase\Countries\CountryCollection.
Loading history...
40
    }
41
42
    /**
43
     * @param string $shortCode
44
     *
45
     * @return null|CountryEntity
46
     */
47 1
    public static function findByShortCode($shortCode)
48
    {
49 1
        if (!isset(self::$items[$shortCode])) {
50 1
            $country = self::getLoader()->loadCountry($shortCode);
51 1
            if (!$country) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $country of type array 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...
52
                return;
53
            }
54
55 1
            return self::$items[$shortCode] = self::getMapper()->mapArrayToEntity($country);
56
        }
57
58
        return self::$items[$shortCode];
59
    }
60
61
    /**
62
     * @return CountryLoader
63
     */
64 2
    private static function getLoader()
65
    {
66 2
        if (null === self::$loader) {
67 1
            self::$loader = new CountryLoader();
68
        }
69
70 2
        return self::$loader;
71
    }
72
73
    /**
74
     * @return CountryMapper
75
     */
76 2
    private static function getMapper()
77
    {
78 2
        if (null === self::$mapper) {
79 1
            self::$mapper = new CountryMapper();
80
        }
81
82 2
        return self::$mapper;
83
    }
84
}
85