Skip to content

Add support for PHP 7.4, but drop support for below PHP 7.1 #27

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 2 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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