docstringWithoutComments()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Kint_Object_Representation_Docstring extends Kint_Object_Representation
0 ignored issues
show
Coding Style introduced by
Kint_Object_Representation_Docstring does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
4
{
5
    public $file = null;
6
    public $line = null;
7
    public $class = null;
8
    public $hints = array('docstring');
9
10
    public function __construct($docstring, $file, $line, $class = null)
11
    {
12
        parent::__construct('Docstring');
13
14
        $this->file = $file;
15
        $this->line = $line;
16
        $this->class = $class;
17
        $this->contents = $docstring;
18
    }
19
20
    /**
21
     * Returns the representation's docstring without surrounding comments.
22
     *
23
     * Note that this will not work flawlessly.
24
     *
25
     * On comments with whitespace after the stars the lines will begin with
26
     * whitespace, since we can't accurately guess how much of an indentation
27
     * is required.
28
     *
29
     * And on lines without stars on the left this may eat bullet points.
30
     *
31
     * Long story short: If you want the docstring read the contents. If you
32
     * absolutely must have it without comments (ie renderValueShort) this will
33
     * probably do.
34
     *
35
     * @return string Docstring with comments stripped
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
36
     */
37
    public function docstringWithoutComments()
38
    {
39
        if (!$this->contents) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->contents of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
40
            return null;
41
        }
42
43
        $string = substr($this->contents, 3, -2);
44
        $string = preg_replace('/^\s*\*\s*?(\S|$)/m', '\1', $string);
45
46
        return trim($string);
47
    }
48
}
49