Completed
Push — master ( 58043b...413e7c )
by Sergi Tur
06:39
created

ProgressBatch::progressable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Acacha\Users\Models;
4
5
use Acacha\Stateful\Contracts\Stateful;
6
use Acacha\Stateful\Traits\StatefulTrait;
7
use Illuminate\Database\Eloquent\Model;
8
9
/**
10
 * Class ProgressBatch.
11
 *
12
 * @package Acacha\Users\Models
13
 */
14
class ProgressBatch extends Model implements Stateful
15
{
16
    use StatefulTrait;
17
18
    /**
19
     * The attributes that are mass assignable.
20
     *
21
     * @var array
22
     */
23
    protected $fillable = ['state', 'accomplished','incidences'];
24
25
    /**
26
     * Progress States
27
     *
28
     * @var array
29
     */
30
    protected $states = [
31
        'pending'  => ['initial' => true],
32
        'stopped' ,
33
        'finished' => ['final' => true]
34
    ];
35
36
    /**
37
     * Transaction State Transitions
38
     *
39
     * @var array
40
     */
41
    protected $transitions = [
42
        'stop' => [
43
            'from' => ['pending'],
44
            'to' => 'stopped'
45
        ],
46
        'resume' => [
47
            'from' => ['stopped'],
48
            'to' => 'pending'
49
        ],
50
        'finish' => [
51
            'from' => ['pending'],
52
            'to' => 'finished'
53
        ]
54
    ];
55
56
    /**
57
     * @return bool
58
     */
59
    protected function validateFinish()
60
    {
61
        if ( ( $this->accomplished != 0 ) || ( $this->incidences !=0 ) ) return true;
0 ignored issues
show
Documentation introduced by
The property accomplished does not exist on object<Acacha\Users\Models\ProgressBatch>. 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 incidences does not exist on object<Acacha\Users\Models\ProgressBatch>. 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...
62
        return false;
63
    }
64
65
    /**
66
     * Get the progressable associated to this batch.
67
     */
68
    public function progressable()
69
    {
70
        return $this->hasMany(UserMigration::class);
71
    }
72
73
}
74
75