Issues (193)

src/Api/Endpoint/AssetEndpoint.php (12 issues)

1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
7
8
class AssetEndpoint extends AbstractEndpoint
9
{
10
    public function findByTheme($themeId, array $fields = array())
11
    {
12
        $params = array();
13
14
        if ($fields) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $fields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
15
            $params['fields'] = implode(',', $fields);
16
        }
17
18
        $request = new GetJson('/admin/themes/' . $themeId . '/assets.json', $params);
19
        $response = $this->send($request);
20
        return $response->get('assets');
21
    }
22
23
    /**
24
     * @param int $themeId
25
     * @param string $assetPath
26
     * @return GenericEntity
0 ignored issues
show
The type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     */
28
    public function findOne($themeId, $assetPath)
29
    {
30
        $params = array(
31
            'asset[key]' => $assetPath,
32
            'theme_id'   => $themeId
33
        );
34
35
        $request = new GetJson('/admin/themes/' . $themeId . '/assets.json', $params);
36
        $response = $this->send($request);
37
        return $this->createEntity($response->get('asset'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...response->get('asset')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
It seems like $response->get('asset') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('asset'));
Loading history...
38
    }
39
40
    /**
41
     * @param int $themeId
42
     * @param string $assetPath
43
     * @param string $templateContent
44
     * @return GenericEntity
45
     */
46
    public function uploadTemplate($themeId, $assetPath, $templateContent)
47
    {
48
        $params = array(
49
            'asset' => array(
50
                'key'   => $assetPath,
51
                'value' => $templateContent
52
            )
53
        );
54
55
        $request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params);
56
        $response = $this->send($request);
57
        return $this->createEntity($response->get('asset'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...response->get('asset')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
It seems like $response->get('asset') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('asset'));
Loading history...
58
    }
59
60
    /**
61
     * @param int $themeId
62
     * @param string $assetPath
63
     * @param string $binary
64
     * @return GenericEntity
65
     */
66
    public function uploadBinaryFile($themeId, $assetPath, $binary)
67
    {
68
        $params = array(
69
            'asset' => array(
70
                'key'   => $assetPath,
71
                'attachment' => base64_encode($binary)
72
            )
73
        );
74
75
        $request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params);
76
        $response = $this->send($request);
77
        return $this->createEntity($response->get('asset'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...response->get('asset')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
It seems like $response->get('asset') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('asset'));
Loading history...
78
    }
79
80
    /**
81
     * @param int $themeId
82
     * @param string $assetPath
83
     * @param string $remoteFileUrl
84
     * @return GenericEntity
85
     */
86
    public function uploadRemoteFile($themeId, $assetPath, $remoteFileUrl)
87
    {
88
        $params = array(
89
            'asset' => array(
90
                'key' => $assetPath,
91
                'src' => $remoteFileUrl
92
            )
93
        );
94
95
        $request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params);
96
        $response = $this->send($request);
97
        return $this->createEntity($response->get('asset'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...response->get('asset')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
It seems like $response->get('asset') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('asset'));
Loading history...
98
    }
99
100
    /**
101
     * @param int $themeId
102
     * @param string $assetPath
103
     * @param string $copySourcePath
104
     * @return GenericEntity
105
     */
106
    public function copy($themeId, $assetPath, $copySourcePath)
107
    {
108
        $params = array(
109
            'asset' => array(
110
                'key'        => $assetPath,
111
                'source_key' => $copySourcePath
112
            )
113
        );
114
115
        $request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params);
116
        $response = $this->send($request);
117
        return $this->createEntity($response->get('asset'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...response->get('asset')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
It seems like $response->get('asset') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('asset'));
Loading history...
118
    }
119
120
    /**
121
     * @param int $themeId
122
     * @param string $assetPath
123
     */
124
    public function delete($themeId, $assetPath)
125
    {
126
        $params = array(
127
            'asset[key]' => $assetPath,
128
            'theme_id'   => $themeId
129
        );
130
131
        $request = new DeleteParams('/admin/themes/' . $themeId . '/assets.json', $params);
132
        $this->send($request);
133
    }
134
}
135