| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 42 | public function testParse() |
||
| 43 | { |
||
| 44 | $document = new \Smalot\PdfParser\Document(array()); |
||
|
|
|||
| 45 | |||
| 46 | // Only_values = false. |
||
| 47 | $content = '/NameType /FlateDecode |
||
| 48 | /Contents[4 0 R 42]/Fonts<</F1 41/F2 43>>/NullType |
||
| 49 | null/StringType(hello)/DateType(D:20130901235555+02\'00\')/XRefType 2 0 R |
||
| 50 | /NumericType 8/HexaType<0020>/BooleanType false'; |
||
| 51 | $offset = 0; |
||
| 52 | $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false); |
||
| 53 | |||
| 54 | $this->assert->array($elements)->hasKey('NameType'); |
||
| 55 | $this->assert->object($elements['NameType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementName'); |
||
| 56 | $this->assert->string($elements['NameType']->getContent())->isEqualTo('FlateDecode'); |
||
| 57 | |||
| 58 | $this->assert->boolean(array_key_exists('Contents', $elements))->isEqualTo(true); |
||
| 59 | $this->assert->object($elements['Contents'])->isInstanceOf('\Smalot\PdfParser\Element\ElementArray'); |
||
| 60 | $this->assert->boolean($elements['Contents']->contains(42))->isEqualTo(true); |
||
| 61 | |||
| 62 | $this->assert->boolean(array_key_exists('Fonts', $elements))->isEqualTo(true); |
||
| 63 | $this->assert->object($elements['Fonts'])->isInstanceOf('\Smalot\PdfParser\Header'); |
||
| 64 | |||
| 65 | $this->assert->boolean(array_key_exists('NullType', $elements))->isEqualTo(true); |
||
| 66 | $this->assert->object($elements['NullType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementNull'); |
||
| 67 | $this->assert->castToString($elements['NullType'])->isEqualTo('null'); |
||
| 68 | |||
| 69 | $this->assert->boolean(array_key_exists('StringType', $elements))->isEqualTo(true); |
||
| 70 | $this->assert->object($elements['StringType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementString'); |
||
| 71 | $this->assert->string($elements['StringType']->getContent())->isEqualTo('hello'); |
||
| 72 | |||
| 73 | $this->assert->boolean(array_key_exists('DateType', $elements))->isEqualTo(true); |
||
| 74 | $this->assert->object($elements['DateType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementDate'); |
||
| 75 | // $this->assert->castToString($elements['DateType'])->isEqualTo('2013-09-01T23:55:55+02:00'); |
||
| 76 | |||
| 77 | $this->assert->boolean(array_key_exists('XRefType', $elements))->isEqualTo(true); |
||
| 78 | $this->assert->object($elements['XRefType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementXRef'); |
||
| 79 | $this->assert->string($elements['XRefType']->getId())->isEqualTo('2_0'); |
||
| 80 | |||
| 81 | $this->assert->boolean(array_key_exists('NumericType', $elements))->isEqualTo(true); |
||
| 82 | $this->assert->object($elements['NumericType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementNumeric'); |
||
| 83 | $this->assert->castToString($elements['NumericType'])->isEqualTo('8'); |
||
| 84 | |||
| 85 | $this->assert->boolean(array_key_exists('HexaType', $elements))->isEqualTo(true); |
||
| 86 | $this->assert->object($elements['HexaType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementString'); |
||
| 87 | $this->assert->string($elements['HexaType']->getContent())->isEqualTo(' '); |
||
| 88 | |||
| 89 | $this->assert->boolean(array_key_exists('BooleanType', $elements))->isEqualTo(true); |
||
| 90 | $this->assert->object($elements['BooleanType'])->isInstanceOf('\Smalot\PdfParser\Element\ElementBoolean'); |
||
| 91 | $this->assert->boolean($elements['BooleanType']->getContent())->isEqualTo(false); |
||
| 92 | |||
| 93 | // Only_values = true. |
||
| 94 | $content = '/NameType /FlateDecode'; |
||
| 95 | $offset = 0; |
||
| 96 | $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, true); |
||
| 97 | $this->assert->array($elements)->hasSize(2); |
||
| 98 | $this->assert->integer($offset)->isEqualTo(22); |
||
| 99 | |||
| 100 | // Test error. |
||
| 101 | $content = '/NameType /FlateDecode $$$'; |
||
| 102 | $offset = 0; |
||
| 103 | $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false); |
||
| 104 | $this->assert->array($elements)->hasSize(1); |
||
| 105 | $this->assert->integer($offset)->isEqualTo(22); |
||
| 106 | $this->assert->string(key($elements))->isEqualTo('NameType'); |
||
| 107 | $this->assert->object(current($elements))->isInstanceOf('\Smalot\PdfParser\Element\ElementName'); |
||
| 108 | |||
| 109 | $content = '/NameType $$$'; |
||
| 110 | $offset = 0; |
||
| 111 | $elements = \Smalot\PdfParser\Element::parse($content, $document, $offset, false); |
||
| 112 | $this->assert->integer($offset)->isEqualTo(0); |
||
| 113 | $this->assert->array($elements)->isEmpty(); |
||
| 114 | |||
| 155 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.