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

ElementName::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
use Smalot\PdfParser\Font;
36
37
/**
38
 * Class ElementName
39
 *
40
 * @package Smalot\PdfParser\Element
41
 */
42
class ElementName extends Element
43
{
44
    /**
45
     * @param string   $value
46
     * @param Document $document
47
     */
48
    public function __construct($value, Document $document = null)
49
    {
50
        parent::__construct($value, null);
51
    }
52
53
    /**
54
     * @param mixed $value
55
     *
56
     * @return bool
57
     */
58
    public function equals($value)
59
    {
60
        return $value == $this->value;
61
    }
62
63
    /**
64
     * @param string   $content
65
     * @param Document $document
66
     * @param int      $offset
67
     *
68
     * @return bool|ElementName
69
     */
70
    public static function parse($content, Document $document = null, &$offset = 0)
71
    {
72
        if (preg_match('/^\s*\/(?P<name>[A-Z0-9\-\+,#\.]+)/is', $content, $match)) {
73
            $name   = $match['name'];
74
            $offset += strpos($content, $name) + strlen($name);
75
            $name   = Font::decodeEntities($name);
76
77
            return new self($name, $document);
78
        }
79
80
        return false;
81
    }
82
}
83