Test Failed
Push — master ( a8b57d...533f3a )
by Dan Michael O.
03:50
created

UserSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 15.56 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 7
loc 45
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 4

8 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 7 7 1
A it_is_initializable() 0 4 1
A it_has_primary_id() 0 4 1
A it_has_barcode() 0 4 1
A it_has_barcodes() 0 4 1
A it_has_university_id() 0 4 1
A it_has_university_ids() 0 4 1
A it_has_identifiers() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace spec\Scriptotek\Alma\Users;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Scriptotek\Alma\Client as AlmaClient;
8
use Scriptotek\Alma\Users\User;
9
use spec\Scriptotek\Alma\SpecHelper;
10
11
class UserSpec extends ObjectBehavior
12
{
13 View Code Duplication
    public function let(AlmaClient $almaClient)
0 ignored issues
show
Duplication introduced by
This method 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...
14
    {
15
        $this->beConstructedWith($almaClient, '12345');
16
17
        $almaClient->getJSON(Argument::containingString('12345'), Argument::any())
18
            ->willReturn(SpecHelper::getDummyData('user_response.json'));
19
    }
20
21
    public function it_is_initializable()
22
    {
23
        $this->shouldHaveType(User::class);
24
    }
25
26
    public function it_has_primary_id()
27
    {
28
        $this->primaryId->shouldBe('12345');
0 ignored issues
show
Documentation introduced by
The property primaryId does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
29
    }
30
31
    public function it_has_barcode()
32
    {
33
        $this->barcode->shouldBe('ub54321');
0 ignored issues
show
Documentation introduced by
The property barcode does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
34
    }
35
36
    public function it_has_barcodes()
37
    {
38
        $this->barcodes->shouldBe(['ub54321', 'ntb12897787']);
0 ignored issues
show
Documentation introduced by
The property barcodes does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
39
    }
40
41
    public function it_has_university_id()
42
    {
43
        $this->universityId->shouldBe('[email protected]');
0 ignored issues
show
Documentation introduced by
The property universityId does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
44
    }
45
46
    public function it_has_university_ids()
47
    {
48
        $this->universityIds->shouldBe(['[email protected]']);
0 ignored issues
show
Documentation introduced by
The property universityIds does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
49
    }
50
51
    public function it_has_identifiers()
52
    {
53
        $this->identifiers->all()->shouldBe(['12345', 'ub54321', 'ntb12897787', '[email protected]']);
0 ignored issues
show
Documentation introduced by
The property identifiers does not exist on object<spec\Scriptotek\Alma\Users\UserSpec>. 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...
54
    }
55
}
56