Test Failed
Push — feature/switch-to-phpunit ( 82614e...d3db35 )
by Konrad
04:06
created

ElementHexaTest::testParse()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 58
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 75
rs 8.9163

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 * @date    2020-06-02
8
 *
9
 * @author  Sébastien MALOT <[email protected]>
10
 * @date    2017-01-03
11
 *
12
 * @license LGPLv3
13
 * @url     <https://github.com/smalot/pdfparser>
14
 *
15
 *  PdfParser is a pdf library written in PHP, extraction oriented.
16
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
17
 *
18
 *  This program is free software: you can redistribute it and/or modify
19
 *  it under the terms of the GNU Lesser General Public License as published by
20
 *  the Free Software Foundation, either version 3 of the License, or
21
 *  (at your option) any later version.
22
 *
23
 *  This program is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU Lesser General Public License for more details.
27
 *
28
 *  You should have received a copy of the GNU Lesser General Public License
29
 *  along with this program.
30
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
31
 */
32
33
namespace Tests\Smalot\PdfParser\Integration\Element;
34
35
use Smalot\PdfParser\Element\ElementDate;
36
use Smalot\PdfParser\Element\ElementHexa;
37
use Smalot\PdfParser\Element\ElementString;
38
use Smalot\PdfParser\Test\TestCase;
39
40
class ElementHexaTest extends TestCase
41
{
42
    public function testParse()
43
    {
44
        // Skipped.
45
        $offset = 0;
46
        $element = ElementHexa::parse('ABC', null, $offset);
47
        $this->assertFalse($element);
0 ignored issues
show
Bug introduced by
$element of type Smalot\PdfParser\Element\ElementHexa is incompatible with the type boolean expected by parameter $condition of PHPUnit\Framework\Assert::assertFalse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        $this->assertFalse(/** @scrutinizer ignore-type */ $element);
Loading history...
48
        $this->assertEquals(0, $offset);
49
50
        $offset = 0;
51
        $element = ElementHexa::parse(' [ <0020> 5 6 ]', null, $offset);
52
        $this->assertFalse($element);
53
        $this->assertEquals(0, $offset);
54
55
        $offset = 0;
56
        $element = ElementHexa::parse(' << <0020> >>', null, $offset);
57
        $this->assertFalse($element);
58
        $this->assertEquals(0, $offset);
59
60
        $offset = 0;
61
        $element = ElementHexa::parse(' / <0020> ', null, $offset);
62
        $this->assertFalse($element);
63
        $this->assertEquals(0, $offset);
64
65
        $offset = 0;
66
        $element = ElementHexa::parse(' 0 <0020> ', null, $offset);
67
        $this->assertFalse($element);
68
        $this->assertEquals(0, $offset);
69
70
        $offset = 0;
71
        $element = ElementHexa::parse(" 0 \n <0020> ", null, $offset);
72
        $this->assertFalse($element);
73
        $this->assertEquals(0, $offset);
74
75
        // Valid.
76
        $offset = 0;
77
        $element = ElementHexa::parse(' <0020> ', null, $offset);
78
        $this->assertEquals(' ', $element->getContent());
79
        $this->assertEquals(7, $offset);
80
81
        $offset = 0;
82
        $element = ElementHexa::parse(' <0020> ', null, $offset);
83
        $this->assertEquals(' ', $element->getContent());
84
        $this->assertEquals(7, $offset);
85
86
        $offset = 0;
87
        $element = ElementHexa::parse(' <0020>', null, $offset);
88
        $this->assertEquals(' ', $element->getContent());
89
        $this->assertEquals(7, $offset);
90
91
        $offset = 0;
92
        $element = ElementHexa::parse('<0020>', null, $offset);
93
        $this->assertEquals(' ', $element->getContent());
94
        $this->assertEquals(6, $offset);
95
96
        $offset = 0;
97
        $element = ElementHexa::parse(" \n <0020> ", null, $offset);
98
        $this->assertEquals(' ', $element->getContent());
99
        $this->assertEquals(9, $offset);
100
101
        $offset = 0;
102
        $element = ElementHexa::parse(" \n <5465616d204d616e6167656d656e742053797374656d73> ", null, $offset);
103
        $this->assertEquals('Team Management Systems', $element->getContent());
104
        $this->assertEquals(51, $offset);
105
106
        $offset = 0;
107
        $element = ElementHexa::parse(" \n <5265706f72744275696c646572> ", null, $offset);
108
        $this->assertTrue($element instanceof ElementString);
109
        $this->assertEquals('ReportBuilder', $element->getContent());
110
        $this->assertEquals(31, $offset);
111
112
        $offset = 0;
113
        $element = ElementHexa::parse(" \n <443a3230313331323137313334303435303027303027> ", null, $offset);
114
        $this->assertTrue($element instanceof ElementDate);
115
        $this->assertEquals('2013-12-17T13:40:45+00:00', (string) $element);
116
        $this->assertEquals(49, $offset);
117
    }
118
}
119