Skip to content

Commit

Permalink
fix: remove warning for using json_decode/strip_tags with null - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Jul 27, 2023
1 parent 4cab6a2 commit 99872d0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/error/PodioError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

class PodioError extends Exception
{
/** @var array|null */
public $body;
public $status;
public $url;
public $request;

/**
* @param string|null $body
* @param int|null $status
* @param string|null $url
*/
public function __construct($body, $status, $url)
{
$this->body = json_decode($body, true);
$this->body = $body !== null ? json_decode($body, true) : null;
$this->status = $status;
$this->url = $url;
$this->request = $this->body['request'] ?? null;
Expand All @@ -17,7 +24,7 @@ public function __construct($body, $status, $url)

public function __toString()
{
$str = $str = get_class($this);
$str = get_class($this);
if (!empty($this->body['error_description'])) {
$str .= ': "'.$this->body['error_description'].'"';
}
Expand Down
2 changes: 1 addition & 1 deletion models/field/PodioDurationItemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __get($name)
} elseif ($name == 'hours') {
return floor($this->values / 3600);
} elseif ($name == 'minutes') {
return (($this->values / 60) % 60);
return (floor($this->values / 60) % 60);
} elseif ($name == 'seconds') {
return ($this->values % 60);
}
Expand Down
2 changes: 1 addition & 1 deletion models/field/PodioTextItemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function set_value($values)

public function humanized_value()
{
return strip_tags($this->values);
return $this->values !== null ? strip_tags($this->values) : '';
}

public function api_friendly_values()
Expand Down
16 changes: 16 additions & 0 deletions tests/PodioErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Podio\Tests;

use PodioError;
use PHPUnit\Framework\TestCase;

class PodioErrorTest extends TestCase
{

public function test__constructShouldOutputNoWarningForEmptyBody()
{
$this->expectOutputString('');
new PodioError(null, null, null);
}
}

0 comments on commit 99872d0

Please sign in to comment.