TranslatableTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetterMethod() 0 5 1
A testProperty() 0 5 1
A testGetterMethodWithNetteObject() 0 5 1
A testPropertyWithNetteObject() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zenify\DoctrineBehaviors\Tests\Translatable\Entities\Attributes;
6
7
use PHPUnit\Framework\TestCase;
8
use Zenify\DoctrineBehaviors\Tests\Translatable\Entities\Attributes\Source\TranslatableEntity;
9
use Zenify\DoctrineBehaviors\Tests\Translatable\Entities\Attributes\Source\TranslatableEntityWithNetteObject;
10
11
12
final class TranslatableTest extends TestCase
13
{
14
15
	public function testGetterMethod()
16
	{
17
		$translatableEntity = new TranslatableEntity;
18
		$this->assertSame('someName', $translatableEntity->getName());
19
	}
20
21
22
	public function testProperty()
23
	{
24
		$translatableEntity = new TranslatableEntity;
25
		$this->assertSame(5, $translatableEntity->position);
0 ignored issues
show
Documentation introduced by
The property position does not exist on object<Zenify\DoctrineBe...rce\TranslatableEntity>. 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...
26
	}
27
28
29
	public function testGetterMethodWithNetteObject()
30
	{
31
		$translatableEntity = new TranslatableEntityWithNetteObject;
32
		$this->assertSame('someName', $translatableEntity->getName());
33
	}
34
35
36
	public function testPropertyWithNetteObject()
37
	{
38
		$translatableEntity = new TranslatableEntityWithNetteObject;
39
		$this->assertSame(5, $translatableEntity->position);
0 ignored issues
show
Documentation introduced by
The property position does not exist on object<Zenify\DoctrineBe...eEntityWithNetteObject>. 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...
40
	}
41
42
}
43