Passed
Branch master (f7fac8)
by Sebastien
02:47
created

ElementNull::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @file
5
 *          This file is part of the PdfParser library.
6
 *
7
 * @author  Sébastien MALOT <[email protected]>
8
 * @date    2017-01-03
9
 * @license LGPLv3
10
 * @url     <https://github.com/smalot/pdfparser>
11
 *
12
 *  PdfParser is a pdf library written in PHP, extraction oriented.
13
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
14
 *
15
 *  This program is free software: you can redistribute it and/or modify
16
 *  it under the terms of the GNU Lesser General Public License as published by
17
 *  the Free Software Foundation, either version 3 of the License, or
18
 *  (at your option) any later version.
19
 *
20
 *  This program is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU Lesser General Public License for more details.
24
 *
25
 *  You should have received a copy of the GNU Lesser General Public License
26
 *  along with this program.
27
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
28
 *
29
 */
30
31
namespace Smalot\PdfParser\Element;
32
33
use Smalot\PdfParser\Element;
34
use Smalot\PdfParser\Document;
35
36
/**
37
 * Class ElementNull
38
 *
39
 * @package Smalot\PdfParser\Element
40
 */
41
class ElementNull extends Element
42
{
43
    /**
44
     * @param string   $value
45
     * @param Document $document
46
     */
47
    public function __construct($value, Document $document = null)
48
    {
49
        parent::__construct(null, null);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function __toString()
56
    {
57
        return 'null';
58
    }
59
60
    /**
61
     * @param mixed $value
62
     *
63
     * @return bool
64
     */
65
    public function equals($value)
66
    {
67
        return ($this->getContent() === $value);
68
    }
69
70
    /**
71
     * @param string   $content
72
     * @param Document $document
73
     * @param int      $offset
74
     *
75
     * @return bool|ElementNull
76
     */
77
    public static function parse($content, Document $document = null, &$offset = 0)
78
    {
79
        if (preg_match('/^\s*(null)/s', $content, $match)) {
80
            $offset += strpos($content, 'null') + strlen('null');
81
82
            return new self(null, $document);
83
        }
84
85
        return false;
86
    }
87
}
88