GeoDealerService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateFromArray() 0 10 2
A hydrateObjectArray() 0 24 5
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Service;
15
16
use Dealer\Dealer;
17
use Dealer\Model\DealerQuery;
18
19
/**
20
 * Class GeoDealerService
21
 * @package Dealer\Service
22
 */
23
class GeoDealerService
24
{
25
    public function updateFromArray($data)
26
    {
27
        $dealer = $this->hydrateObjectArray($data);
28
29
        if ($dealer) {
30
            $dealer->save();
31
        }
32
33
        return $dealer;
34
    }
35
36
    protected function hydrateObjectArray($data)
37
    {
38
        $model = new Dealer();
39
40
        if (isset($data['id'])) {
41
            $dealer = DealerQuery::create()->findOneById($data['id']);
42
            if ($dealer) {
43
                $model = $dealer;
44
            }
45
        } else {
46
            return null;
47
        }
48
49
        if (isset($data['latitude'])) {
50
            $model->setLatitude($data['latitude']);
51
        }
52
53
        if (isset($data['longitude'])) {
54
            $model->setLongitude($data['longitude']);
55
        }
56
57
58
        return $model;
59
    }
60
}
61