Skip to content

Commit

Permalink
Update phpstan and fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed Sep 13, 2022
1 parent a8cbebf commit a911ec3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"jacobsteringa/odoo-client": "<=0.3.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.32 || ^1.0.0",
"squizlabs/php_codesniffer": "^3.5"
"phpstan/phpstan": "^1",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan-deprecation-rules": "^1",
"phpstan/phpstan-symfony": "^1"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ parameters:
level: max
paths:
- .
excludes_analyse:
excludePaths:
- vendor
35 changes: 21 additions & 14 deletions src/Odoo/Odoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Odoo
/**
* Unique identifier for current user
*
* @var integer
* @var integer|null
*/
protected $uid;
protected $uid = null;

/**
* Current users username
Expand Down Expand Up @@ -112,23 +112,25 @@ public function version(): array
{
$response = $this->getClient('common')->call('version');

return $response;
return is_array($response) ? $response : [];
}

/**
* Get timezone
*
* @return string Current timezone
*/
public function timezone(): string
public function timezone(): ?string
{
$params = [
$this->database,
$this->user,
$this->password
];

return $this->getClient('common')->call('timezone_get', $params);
$response = $this->getClient('common')->call('timezone_get', $params);

return is_string($response) ? $response : null;
}

/**
Expand All @@ -153,7 +155,7 @@ public function search(string $model, array $data, int $offset = 0, int $limit =

$response = $this->getClient('object')->call('execute', $params);

return $response;
return is_array($response) ? $response : [];
}

/**
Expand All @@ -164,7 +166,7 @@ public function search(string $model, array $data, int $offset = 0, int $limit =
*
* @return integer Created model id
*/
public function create(string $model, array $data): int
public function create(string $model, array $data): ?int
{
$params = $this->buildParams([
$model,
Expand All @@ -174,7 +176,7 @@ public function create(string $model, array $data): int

$response = $this->getClient('object')->call('execute', $params);

return $response;
return is_int($response) ? $response : null;
}

/**
Expand All @@ -197,7 +199,7 @@ public function read(string $model, array $ids, array $fields = []): array

$response = $this->getClient('object')->call('execute', $params);

return $response;
return is_array($response) ? $response : [];
}

/**
Expand Down Expand Up @@ -229,7 +231,7 @@ public function searchRead(

$response = $this->getClient('object')->call('execute', $params);

return $response;
return is_array($response) ? $response : [];
}

/**
Expand All @@ -252,7 +254,7 @@ public function write(string $model, array $ids, array $fields): array

$response = $this->getClient('object')->call('execute', $params);

return $response;
return is_array($response) ? $response : [];
}

/**
Expand All @@ -271,7 +273,9 @@ public function unlink(string $model, array $ids): bool
$ids
]);

return $this->getClient('object')->call('execute', $params);
$response = $this->getClient('object')->call('execute', $params);

return is_bool($response) ? $response : false;
}

/**
Expand Down Expand Up @@ -302,6 +306,7 @@ public function getReport(string $model, array $ids, string $type = 'qweb-pdf'):
$state = false;

while (!$state) {
/** @var array<string> */
$report = $client->call(
'report_get',
$this->buildParams([$reportId])
Expand Down Expand Up @@ -401,16 +406,18 @@ protected function getClient(?string $path = null): XmlRpcClient
*
* @return int $uid
*/
protected function uid(): int
protected function uid(): ?int
{
if ($this->uid === null) {
$client = $this->getClient('common');

$this->uid = $client->call('login', [
$response = $client->call('login', [
$this->database,
$this->user,
$this->password
]);

$this->uid = is_int($response) ? $response : null;
}

return $this->uid;
Expand Down

0 comments on commit a911ec3

Please sign in to comment.