Completed
Push — master ( 33ec04...ed9cfc )
by Bart
11s
created

src/Converters/Fields/Assets.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
namespace NerdsAndCompany\Schematic\Converters\Fields;
4
5
use Craft;
6
use craft\base\Model;
7
use NerdsAndCompany\Schematic\Schematic;
8
use NerdsAndCompany\Schematic\Converters\Base\Field;
9
10
/**
11
 * Schematic Asset Converter.
12
 *
13
 * Sync Craft Setups.
14
 *
15
 * @author    Nerds & Company
16
 * @copyright Copyright (c) 2015-2018, Nerds & Company
17
 * @license   MIT
18
 *
19
 * @see      http://www.nerds.company
20
 */
21
class Assets extends Field
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getRecordDefinition(Model $record): array
27
    {
28
        $definition = parent::getRecordDefinition($record);
29
30
        unset($definition['attributes']['targetSiteId']);
31
32
        if (isset($definition['attributes']['defaultUploadLocationSource'])) {
33
            $definition['attributes']['defaultUploadLocationSource'] = $this->getSource(
0 ignored issues
show
Documentation Bug introduced by
The method getSource does not exist on object<NerdsAndCompany\S...nverters\Fields\Assets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
                $definition['class'],
35
                $definition['attributes']['defaultUploadLocationSource'],
36
                'id',
37
                'handle'
38
            );
39
        }
40
41
        if (isset($definition['attributes']['singleUploadLocationSource'])) {
42
            $definition['attributes']['singleUploadLocationSource'] = $this->getSource(
0 ignored issues
show
Documentation Bug introduced by
The method getSource does not exist on object<NerdsAndCompany\S...nverters\Fields\Assets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
43
                $definition['class'],
44
                $definition['attributes']['singleUploadLocationSource'],
45
                'id',
46
                'handle'
47
            );
48
        }
49
50
        return $definition;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function setRecordAttributes(Model &$record, array $definition, array $defaultAttributes): void
57
    {
58
        if (isset($definition['attributes']['defaultUploadLocationSource'])) {
59
            $definition['attributes']['defaultUploadLocationSource'] = $this->getSource(
0 ignored issues
show
Documentation Bug introduced by
The method getSource does not exist on object<NerdsAndCompany\S...nverters\Fields\Assets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
60
                $definition['class'],
61
                $definition['attributes']['defaultUploadLocationSource'],
62
                'handle',
63
                'id'
64
            );
65
        }
66
67
        if (isset($definition['attributes']['singleUploadLocationSource'])) {
68
            $definition['attributes']['singleUploadLocationSource'] = $this->getSource(
0 ignored issues
show
Documentation Bug introduced by
The method getSource does not exist on object<NerdsAndCompany\S...nverters\Fields\Assets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
69
                $definition['class'],
70
                $definition['attributes']['singleUploadLocationSource'],
71
                'handle',
72
                'id'
73
            );
74
        }
75
76
        parent::setRecordAttributes($record, $definition, $defaultAttributes);
77
    }
78
}
79