Skip to content

Commit

Permalink
Merge pull request #27 from amcsi/master
Browse files Browse the repository at this point in the history
Add support for PHP 7.4, but drop support for below PHP 7.1
  • Loading branch information
mlanin authored Jul 9, 2020
2 parents ab412ad + a4bc6ef commit eed485a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ dist: trusty
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

sudo: false

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ When you are developing JSON API sometimes you need to debug it, but if you will

To get the latest version of Laravel Laravel-API-Debugger, simply add the following line to the require block of your `composer.json` file.

For PHP >= 7.1:

```
"lanin/laravel-api-debugger": "^4.0"
```

For PHP < 7.1:

```
"lanin/laravel-api-debugger": "^3.0"
```
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.1",
"illuminate/support": ">=5.4.0"
},
"require-dev": {
"orchestra/testbench": ">=3.4.0",
"phpunit/phpunit": ">=5.7",
"mockery/mockery": "0.9.*"
"phpunit/phpunit": "^7",
"mockery/mockery": "^1.3.1"
},
"autoload": {
"psr-4": {
Expand Down
63 changes: 25 additions & 38 deletions src/Collections/QueriesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,31 @@ protected function convertAttribute($attribute)
try {
return (string) $attribute;
} catch (\Throwable $e) {
return $this->handleConvertAttributeException($attribute);
} catch (\Exception $e) {
return $this->handleConvertAttributeException($attribute);
}
}

/**
* Handle convert attribute exception and convert attribute to string.
*
* @param mixed $attribute
* @return string
*/
protected function handleConvertAttributeException($attribute)
{
switch (true) {
// Handle DateTime attribute pass.
case $attribute instanceof \DateTime:
return $attribute->format('Y-m-d H:i:s');

// Handle callables.
case $attribute instanceof \Closure:
return $this->convertAttribute($attribute());

// Handle arrays using json by default or print_r if error occurred.
case is_array($attribute):
$json = json_encode($attribute);

return json_last_error() === JSON_ERROR_NONE
? $json
: print_r($attribute);

// Handle all other object.
case is_object($attribute):
return get_class($attribute);

// For all unknown.
default:
return '?';
switch (true) {
// Handle DateTime attribute pass.
case $attribute instanceof \DateTime:
return $attribute->format('Y-m-d H:i:s');

// Handle callables.
case $attribute instanceof \Closure:
return $this->convertAttribute($attribute());

// Handle arrays using json by default or print_r if error occurred.
case is_array($attribute):
$json = json_encode($attribute);

return json_last_error() === JSON_ERROR_NONE
? $json
: print_r($attribute);

// Handle all other object.
case is_object($attribute):
return get_class($attribute);

// For all unknown.
default:
return '?';
}
}
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class TestCase extends BaseTestCase
/**
* Setup the test environment.
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
}
Expand Down

0 comments on commit eed485a

Please sign in to comment.