DeliveryOptionHtmlMapper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 15 1
A parseFloat() 0 4 1
1
<?php
2
3
namespace Jne\Mappers\HtmlMappers;
4
5
use Jne\DeliveryOption;
6
use Jne\Contracts\HtmlMapperInterface;
7
use Symfony\Component\DomCrawler\Crawler;
8
9
class DeliveryOptionHtmlMapper implements HtmlMapperInterface
10
{
11
    /**
12
     * Map HTML DOM data to instance of object.
13
     *
14
     * @param \Symfony\Component\DomCrawler\Crawler $node
15
     *
16
     * @return mixed
17
     */
18 2
    public function map(Crawler $node)
19
    {
20 2
        $table = $node->filter('table')->eq(1);
21
22 2
        return $table->filter('tbody > tr')->each(function (Crawler $row) {
23 2
            $cols = $row->children();
24
25 2
            return new DeliveryOption(
26 2
                $cols->eq(0)->text(),
27 2
                $cols->eq(1)->text(),
28 2
                $this->parseFloat($cols->eq(2)->text()),
29 2
                $cols->eq(3)->text()
30 2
            );
31 2
        });
32
    }
33
34
    /**
35
     * Parse to float.
36
     *
37
     * @param string $number
38
     *
39
     * @return float
40
     */
41 2
    protected function parseFloat($number)
42
    {
43 2
        return (float) preg_replace('/[^0-9]/', '', $number);
44
    }
45
}
46