Completed
Push — signal_search_issues ( 5556b2...f328ba )
by André
63:06 queued 07:22
created

PriceMapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canMap() 0 4 1
A map() 0 4 1
1
<?php
2
3
/**
4
 * File containing the PriceMapper document field value mapper class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper;
12
13
use eZ\Publish\Core\Search\Elasticsearch\Content\FieldValueMapper;
14
use eZ\Publish\SPI\Search\FieldType\PriceField;
15
use eZ\Publish\SPI\Search\Field;
16
17
/**
18
 * Maps PriceField document field values to something Elasticsearch can index.
19
 */
20
class PriceMapper extends FieldValueMapper
21
{
22
    /**
23
     * Check if field can be mapped.
24
     *
25
     * @param \eZ\Publish\SPI\Search\Field $field
26
     *
27
     * @return bool
28
     */
29
    public function canMap(Field $field)
30
    {
31
        return $field->type instanceof PriceField;
0 ignored issues
show
Documentation introduced by
The property $type is declared protected in eZ\Publish\SPI\Search\Field. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
32
    }
33
34
    /**
35
     * Map field value to a proper Elasticsearch representation.
36
     *
37
     * @param \eZ\Publish\SPI\Search\Field $field
38
     *
39
     * @return mixed
40
     */
41
    public function map(Field $field)
42
    {
43
        return (double)$field->value;
0 ignored issues
show
Documentation introduced by
The property $value is declared protected in eZ\Publish\SPI\Search\Field. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
44
    }
45
}
46