LocationChoice   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadChoiceList() 0 5 1
A getLocationCities() 0 12 3
1
<?php
2
namespace Dwr\GlobalWeatherBundle\Form;
3
4
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
5
6
class LocationChoice
7
{
8
9
    private $locationParameters;
10
11
    public function __construct(array $locationParameters)
12
    {
13
        $this->locationParameters = $locationParameters;
14
    }
15
16
    /**
17
     * @return ArrayChoiceList
18
     */
19
    public function loadChoiceList()
20
    {
21
        $choices = $this->getLocationCities($this->locationParameters);
22
        return new ArrayChoiceList($choices);
23
    }
24
25
    /**
26
     * @param $locations
27
     * @return array
28
     */
29
    private function getLocationCities($locations)
30
    {
31
        $data = [];
32
        foreach ($locations as $country => $cities) {
33
            foreach ($cities as $city) {
34
                $location = sprintf('%s, %s', $country, $city);
35
                $data[$location] = $location;
36
            }
37
        }
38
39
        return $data;
40
    }
41
}
42