SearchAnnotation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 1
dl 0
loc 17
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL-3.0-only, proprietary
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Annotations;
14
15
use Maslosoft\Manganel\Meta\ManganelTypeAnnotation;
16
17
/**
18
 * SearchAnnotation
19
 * @Target('property')
20
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
21
 */
22
class SearchAnnotation extends ManganelTypeAnnotation
23
{
24
25
	const Ns = __NAMESPACE__;
26
27
	/**
28
	 * Whether to search field
29
	 * @var boolean
30
	 */
31
	public $value = true;
32
33 3
	public function init()
34
	{
35 3
		$this->getEntity()->searchable = (bool) $this->value;
0 ignored issues
show
Documentation introduced by
The property searchable does not exist on object<Maslosoft\Manganel\Meta\DocumentTypeMeta>. 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...
36 3
	}
37
38
}
39