GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

InstanceResource::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace prgTW\BaseCRM\Resource;
4
5
use prgTW\BaseCRM\Exception\ResourceException;
6
use prgTW\BaseCRM\Service\Behavior\CustomFieldsTrait;
7
use prgTW\BaseCRM\Service\Enum\CustomFields;
8
9
abstract class InstanceResource extends LazyLoadedResource
10
{
11
	use CustomFieldsTrait;
12
13
	/**
14
	 * @throws \InvalidArgumentException when resource key is not found in the response
15
	 * @return $this
16
	 */
17
	public function get()
18
	{
19
		$uri          = $this->getFullUri();
20
		$resourceName = $this->getResourceName();
21
		$data         = $this->transport->get($uri, $resourceName);
22
23
		$this->hydrate($data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by $this->transport->get($uri, $resourceName) on line 21 can also be of type boolean; however, prgTW\BaseCRM\Resource\BaseResource::hydrate() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
24
25
		return $this;
26
	}
27
28
	/**
29
	 * @param array $fieldNames
30
	 *
31
	 * @throws ResourceException when there's no data to save
32
	 * @return $this
33
	 */
34
	public function save(array $fieldNames = [])
35
	{
36
		if ([] === $fieldNames)
37
		{
38
			$fieldNames = array_keys($this->data);
39
			if ([] === $fieldNames)
40
			{
41
				//@codeCoverageIgnoreStart
42
				throw new ResourceException('No data to save');
43
				//@codeCoverageIgnoreEnd
44
			}
45
46
			return $this->save($fieldNames);
47
		}
48
		$resourceName = $this->getResourceName();
49
		$uri          = $this->getFullUri();
50
		$data         = $this->dehydrate($fieldNames);
51
52
		if (in_array(CustomFieldsTrait::class, class_uses($this)))
53
		{
54
			/** @noinspection PhpUndefinedMethodInspection */
55
			$customFields = $this->getCustomFields()->toArray();
56
			if ([] !== $customFields)
57
			{
58
				$data[CustomFields::KEY_SAVING] = $customFields;
59
			}
60
		}
61
62
		$response = $this->transport->put($uri, $resourceName, [
63
			'query' => [
64
				$resourceName => $data,
65
			],
66
		]);
67
		$this->hydrate($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->transport->put($u...esourceName => $data))) on line 62 can also be of type boolean; however, prgTW\BaseCRM\Resource\BaseResource::hydrate() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
68
69
		return $this;
70
	}
71
72
	/** {@inheritdoc} */
73
	protected function lazyLoad()
74
	{
75
		$this->get();
76
	}
77
}
78