DeliveryOptionHtmlMapper::map()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 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