Completed
Push — master ( ca1336...ce2897 )
by Adrien
07:43
created

Status::getDateUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 59.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace mQueue\Model;
4
5
use mQueue\Model\Status as DefaultModelStatus;
6
use Zend_Date;
7
8
/**
9
 * A status (link between movie and user with a rating)
10
 */
11
class Status extends AbstractModel
12
{
13
    const Nothing = 0;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected NOTHING).
Loading history...
14
    const Need = 1;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected NEED).
Loading history...
15
    const Bad = 2;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected BAD).
Loading history...
16
    const Ok = 3;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected OK).
Loading history...
17
    const Excellent = 4;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected EXCELLENT).
Loading history...
18
    const Favorite = 5;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected FAVORITE).
Loading history...
19
20
    /**
21
     * array of ratings names indexed by the rating value
22
     * @var array
23
     */
24
    public static $ratings = null;
25
26
    /**
27
     * Returns the unique ID for this status to be used in HTML
28
     * @return string
29
     */
30 1
    public function getUniqueId()
31
    {
32 1
        return $this->idMovie . '_' . $this->idUser;
0 ignored issues
show
Documentation introduced by
The property idMovie does not exist on object<mQueue\Model\Status>. 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...
Documentation introduced by
The property idUser does not exist on object<mQueue\Model\Status>. 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...
33
    }
34
35
    /**
36
     * Returns the name
37
     * @return string
38
     */
39
    public function getName()
40
    {
41
        if ($this->rating == 0) {
0 ignored issues
show
Bug introduced by
The property rating does not seem to exist. Did you mean ratings?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
            return _tr('Not rated');
43
        }
44
45
        return self::$ratings[$this->rating];
0 ignored issues
show
Bug introduced by
The property rating does not seem to exist. Did you mean ratings?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
    }
47
48
    /**
49
     * Returns the date of last udpate
50
     * @return Zend_Date
51
     */
52
    public function getDateUpdate()
53
    {
54
        return new Zend_Date($this->dateUpdate, Zend_Date::ISO_8601);
0 ignored issues
show
Documentation introduced by
The property dateUpdate does not exist on object<mQueue\Model\Status>. 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...
55
    }
56
}
57
58
// Defines ratings names
59
\mQueue\Model\Status::$ratings = [
60 1
    DefaultModelStatus::Need => _tr('Need'),
61 1
    DefaultModelStatus::Bad => _tr('Bad'),
62 1
    DefaultModelStatus::Ok => _tr('Ok'),
63 1
    DefaultModelStatus::Excellent => _tr('Excellent'),
64
    DefaultModelStatus::Favorite => _tr('Favorite'), ];
65