PollsAnswer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A _getPercentage() 0 8 2
1
<?php
2
namespace App\Model\Entity;
3
4
use Cake\ORM\Entity;
5
6
/**
7
 * PollsAnswer Entity
8
 *
9
 * @property int $id
10
 * @property int $poll_id
11
 * @property string $response
12
 * @property int $user_count
13
 * @property \Cake\I18n\Time $created
14
 * @property \Cake\I18n\Time $modified
15
 *
16
 * @property \App\Model\Entity\Poll $poll
17
 */
18
class PollsAnswer extends Entity
19
{
20
21
    /**
22
     * Fields that can be mass assigned using newEntity() or patchEntity().
23
     *
24
     * @var array
25
     */
26
    protected $_accessible = [
27
        '*' => true,
28
        'id' => false
29
    ];
30
31
    /**
32
     * Get the percentage of the answer's vote relative to the total of vote.
33
     *
34
     * @return int
35
     */
36
    protected function _getPercentage()
37
    {
38
        if ($this->poll->user_count != 0) {
0 ignored issues
show
Documentation introduced by
The property user_count does not exist on object<App\Model\Entity\Poll>. 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
            return ($this->user_count * 100) / $this->poll->user_count;
0 ignored issues
show
Documentation introduced by
The property user_count does not exist on object<App\Model\Entity\Poll>. 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
        return $this->poll->user_count;
0 ignored issues
show
Documentation introduced by
The property user_count does not exist on object<App\Model\Entity\Poll>. 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...
43
    }
44
}
45