NodeListFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Dom\Factory;
12
13
use DOMNodeList as DomNodeList;
14
use WebinoDraw\Dom\Locator;
15
use WebinoDraw\Dom\NodeList;
16
use WebinoDraw\Exception\InvalidArgumentException;
17
18
/**
19
 * Batch DOMElement manipulation
20
 */
21
class NodeListFactory
22
{
23
    /**
24
     * @var Locator
25
     */
26
    protected $locator;
27
28
    /**
29
     * @param Locator $locator
30
     */
31
    public function __construct(Locator $locator)
32
    {
33
        $this->locator = $locator;
34
    }
35
36
    /**
37
     * @param array|DomNodeList $nodes DOMNodes in array or DOMNodelist
38
     * @return NodeList
39
     * @throws InvalidArgumentException
40
     */
41
    public function create($nodes)
42
    {
43
        if (!is_array($nodes) && !($nodes instanceof DomNodeList)) {
44
            throw new InvalidArgumentException('Expected nodes as array|DomNodeList');
45
        }
46
47
        return new NodeList($this->locator, $nodes);
48
    }
49
}
50