Test Failed
Push — master ( 50ebf9...195aca )
by Gabriel
12:00 queued 12s
created

MediaRecord::getMediaFilesystemDisk()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace ByTIC\DocumentGenerator\Tests\Fixtures\Models\MediaRecords;
4
5
use ByTIC\MediaLibrary\HasMedia\HasMediaTrait;
6
use ByTIC\MediaLibrary\HasMedia\Interfaces\HasMedia;
7
use League\Flysystem\Adapter\Local as LocalAdapter;
8
use Nip\Filesystem\FileDisk;
9
use Nip\Records\Record;
10
11
/**
12
 * Class MediaRecord
13
 * @package ByTIC\DocumentGenerator\Tests\Fixtures\Models\MediaRecords
14
 */
15 View Code Duplication
class MediaRecord extends Record implements HasMedia
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    use HasMediaTrait;
18
19
    /**
20
     * @return FileDisk
21
     */
22
    public function getMediaFilesystemDisk()
23
    {
24
        if (!isset($this->disk)) {
25
            $this->disk = new FileDisk(
0 ignored issues
show
Documentation introduced by
The property disk does not exist on object<ByTIC\DocumentGen...diaRecords\MediaRecord>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
                new LocalAdapter(
27
                    TEST_FIXTURE_PATH
28
                )
29
            );
30
        }
31
        return $this->disk;
0 ignored issues
show
Documentation introduced by
The property disk does not exist on object<ByTIC\DocumentGen...diaRecords\MediaRecord>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32
    }
33
}
34