Completed
Push — master ( 24c968...d77ed5 )
by Hannes
05:04
created

Reader::hasDataFor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Runalyze DEM Reader.
5
 *
6
 * (c) RUNALYZE <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Runalyze\DEM;
13
14
use Runalyze\DEM\Provider\ProviderInterface;
15
16
class Reader implements ReaderInterface
17
{
18
    /** @var \Runalyze\DEM\Provider\ProviderInterface[] */
19
    protected $Provider = [];
20
21
    /** @var int */
22
    protected $InvalidFlag = 0x8000;
23
24
    /**
25
     * @param \Runalyze\DEM\Provider\ProviderInterface|null $provider
26
     */
27
    public function __construct(ProviderInterface $provider = null)
28
    {
29
        if (null !== $provider) {
30
            $this->addProvider($provider);
31
        }
32
    }
33
34
    /**
35
     * @param \Runalyze\DEM\Provider\ProviderInterface $provider
36
     */
37
    public function addProvider(ProviderInterface $provider)
38
    {
39
        $this->Provider[] = $provider;
40
    }
41
42
    /**
43
     * @return int
44
     */
45
    public function numberOfProviders()
46
    {
47
        return count($this->Provider);
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function hasProviders()
54
    {
55
        return !empty($this->Provider);
56
    }
57
58
    /**
59
     * @param  array $latitudeLongitudes array(array($lat, $lng), ...)
60
     * @return bool
61
     */
62
    public function hasDataFor(array $latitudeLongitudes)
63
    {
64
        foreach ($this->Provider as $provider) {
65
            if ($provider->hasDataFor($latitudeLongitudes)) {
66
                return true;
67
            }
68
        }
69
70
        return false;
71
    }
72
73
    /**
74
     * @param  array                     $latitudes
75
     * @param  array                     $longitudes
76
     * @throws \InvalidArgumentException
77
     * @return array                     elevations [m] can be false if nothing retrieved
78
     */
79
    public function getElevations(array $latitudes, array $longitudes)
80
    {
81
        // TODO
82
83
        // loop through providers
84
        // set all 'false' elevations to $this->InvalidFlag
85
    }
86
}
87