Skip to content

Throw exception instead of getting a php warning #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Exception/NotCallableResourceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*****************************************************************************
*
* PROJECT: MTA PHP SDK
* LICENSE: See LICENSE in the top level directory
* FILE: NotCallableResourceException.php
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

declare(strict_types=1);

namespace MultiTheftAuto\Sdk\Exception;

class NotCallableResourceException extends MessageException
{
protected const EXCEPTION_MESSAGE = 'There was a problem with the request. Ensure that the resource handling the call is running.';
}
9 changes: 7 additions & 2 deletions src/Transformer/ElementTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace MultiTheftAuto\Sdk\Transformer;

use MultiTheftAuto\Sdk\Exception\NotCallableResourceException;
use MultiTheftAuto\Sdk\Factory\ElementFactory;

abstract class ElementTransformer
Expand All @@ -29,8 +30,12 @@ public static function fromServer(?string $dataFromServer): ?array

$data = json_decode($dataFromServer);

foreach ($data as &$value) {
ElementTransformer::stringValuesToObjects($value);
if ($data !== NULL) {
foreach ($data as &$value) {
ElementTransformer::stringValuesToObjects($value);
}
} else {
throw new NotCallableResourceException();
}

return $data;
Expand Down