Completed
Pull Request — develop (#27)
by Chris
12:14
created

AttributeObject::transform()   C

Complexity

Conditions 8
Paths 16

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
rs 5.3846
cc 8
eloc 15
nc 16
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Transformer\AnnotationReadable;
4
5
class AttributeObject implements TransformerInterface
6
{
7
    public function transform($attribute)
8
    {
9
        foreach ($this->getRefProperties() as $refProp) {
10
            $transformer = $this->reader->getPropertyAnnotation($refProp, Transformer::class);
0 ignored issues
show
Unused Code introduced by
$transformer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
11
            if (null === $transform) {
0 ignored issues
show
Bug introduced by
The variable $transform does not exist. Did you mean $transformer?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
12
                continue;
13
            }
14
15
            $value = null === $this->getResult() ? null : $refProp->getValue($this->getResult());
16
            if (null !== $value) {
17
                continue;
18
            }
19
20
            if ($m3u8 instanceof ReaderAwareInterface) {
0 ignored issues
show
Bug introduced by
The class Chrisyue\PhpM3u8\Transfo...le\ReaderAwareInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
21
                $m3u8->setReader($this->reader);
0 ignored issues
show
Bug introduced by
The variable $m3u8 does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
22
            }
23
24
            $parsed = $m3u8->setStream($this->getStream())->parse()->getResult();
25
            if (null !== $parsed) {
26
                is_array($value) ? $value[] = $parsed : $value = $parsed;
27
                $refProp->setValue($this->ensureResult(), $value);
28
29
                break;
30
            }
31
        }
32
    }
33
34
    public function reverse($object)
35
    {
36
    }
37
}
38