Collection::fromHtml()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Jne\Collections;
4
5
use Jne\Contracts\MapperInterface;
6
use Jne\Contracts\HtmlMapperInterface;
7
use Symfony\Component\DomCrawler\Crawler;
8
use Illuminate\Support\Collection as BaseCollection;
9
use Jne\Contracts\Collections\CollectionInterface;
10
11
class Collection extends BaseCollection implements CollectionInterface
12
{
13
    /**
14
     * Create collection instance from raw array.
15
     *
16
     * @param array                          $data
17
     * @param \Jne\Contracts\MapperInterface $mapper
18
     *
19
     * @return \Jne\Contracts\CollectionsInterface
20
     */
21 4
    public static function fromArray(array $data, MapperInterface $mapper)
22
    {
23 4
        return new static($mapper->map($data));
24
    }
25
26
    /**
27
     * Create collection instance from HTML node.
28
     *
29
     * @param \Symfony\Component\DomCrawler\Crawler $node
30
     * @param \Jne\Contracts\HtmlMapperInterface    $htmlMapper
31
     *
32
     * @return \Jne\Contracts\CollectionsInterface
33
     */
34 2
    public static function fromHtml(Crawler $node, HtmlMapperInterface $htmlMapper)
35
    {
36 2
        return new static($htmlMapper->map($node));
37
    }
38
}
39