Test Failed
Push — master ( 36165a...48d6cb )
by vistart
17:09
created

queries/BaseMongoBlameableQuery.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\base\models\queries;
14
15
use MongoDB\BSON\Binary;
16
use rhosocial\base\models\models\BaseUserModel;
17
use rhosocial\base\models\traits\BlameableQueryTrait;
18
use Yii;
19
20
/**
21
 * Description of BaseMongoBlameableQuery
22
 *
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class BaseMongoBlameableQuery extends BaseMongoEntityQuery
27
{
28
    use BlameableQueryTrait;
29
30
    /**
31
     * Specify creator(s).
32
     * @param string|array $guid
33
     * @return $this
34
     */
35 9
    public function createdBy($guid)
36
    {
37 9
        $model = $this->noInitModel;
38 9
        if (!is_string($model->createdByAttribute)) {
0 ignored issues
show
The property createdByAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. 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;
40
        }
41 9
        if ($guid instanceof BaseUserModel) {
42 3
            $guid = $guid->getGUID();
43
        }
44 9
        return $this->andWhere([$model->createdByAttribute => new Binary($guid, Binary::TYPE_UUID)]);
0 ignored issues
show
The property createdByAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. 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...
45
    }
46
47
    /**
48
     * Specify last updater(s).
49
     * @param string|array $guid
50
     * @return $this
51
     */
52 4
    public function updatedBy($guid)
53
    {
54 4
        $model = $this->noInitModel;
55 4
        if (!is_string($model->updatedByAttribute)) {
0 ignored issues
show
The property updatedByAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. 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...
56 1
            return $this;
57
        }
58 3
        if ($guid instanceof BaseUserModel) {
59 3
            $guid = $guid->getGUID();
60
        }
61 3
        return $this->andWhere([$model->updatedByAttribute => new Binary($guid, Binary::TYPE_UUID)]);
0 ignored issues
show
The property updatedByAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. 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
    }
63
64
    /**
65
     * Attach current identity to createdBy condition.
66
     * @param BaseUserModel $identity
67
     * @return $this
68
     */
69 6
    public function byIdentity($identity = null)
70
    {
71 6
        if (!$identity) {
72 1
            $identity = Yii::$app->user->identity;
73
        }
74 6
        if (method_exists($identity, 'canGetProperty') && !$identity->canGetProperty('guid')) {
75
            return $this;
76
        }
77 6
        return $this->createdBy($identity->getGUID());
78
    }
79
}
80