Passed
Push — v1 ( 061017...1b920b )
by Andrew
11:00 queued 06:43
created

src/base/FluentModel.php (19 issues)

1
<?php
2
/**
3
 * Twigfield for Craft CMS
4
 *
5
 * Provides a twig editor field with Twig & Craft API autocomplete
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2022 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\twigfield\base;
12
13
use Craft;
14
use craft\base\Model;
15
use yii\base\InvalidArgumentException;
16
17
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
18
 * @author    nystudio107
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
19
 * @package   Twigfield
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
20
 * @since     1.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
21
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
22
abstract class FluentModel extends Model
23
{
24
25
    // Public Methods
26
    // =========================================================================
27
28
    /**
29
     * Add fluent getters/setters for this class
30
     *
31
     * @param string $method The method name (property name)
32
     * @param array $args The arguments list
0 ignored issues
show
Expected 2 spaces after parameter type; 1 found
Loading history...
Expected 3 spaces after parameter name; 1 found
Loading history...
33
     *
34
     * @return mixed The value of the property
35
     */
36
    public function __call($method, $args)
37
    {
38
        try {
39
            $reflector = new \ReflectionClass(static::class);
40
        } catch (\ReflectionException $e) {
41
            Craft::error(
42
                $e->getMessage(),
43
                __METHOD__
44
            );
45
46
            return null;
47
        }
48
        if (!$reflector->hasProperty($method)) {
49
            throw new InvalidArgumentException("Property {$method} doesn't exist");
50
        }
51
        $property = $reflector->getProperty($method);
52
        if (empty($args)) {
53
            // Return the property
54
            return $property->getValue();
55
        }
56
        // Set the property
57
        $value = $args[0];
58
        $property->setValue($this, $value);
59
60
        // Make it chainable
61
        return $this;
62
    }
63
}
64