Skip to content

Commit

Permalink
Merge pull request #1 from craig-mcmahon/php8-compatability
Browse files Browse the repository at this point in the history
Improve php8 compatability
  • Loading branch information
M1ke authored Sep 25, 2023
2 parents 9107dd5 + 4335b72 commit ac0532a
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ composer.phar
/composer.lock
/phpunit.xml
/phpunit.phar
/zoopla
/zoopla
.phpunit.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"php": ">=7.2",
"ext-json": "*",
"myclabs/php-enum": "1.*",
"guzzlehttp/guzzle": "^6.0.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"justinrainbow/json-schema": "^5.2.10"
},
"require-dev": {
"phpunit/phpunit": "7.*"
"phpunit/phpunit": "9.*"
},
"autoload": {
"psr-4": {
Expand Down
43 changes: 20 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap = "vendor/autoload.php"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
stopOnFailure = "true">

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="Zoopla Test">
<directory>./tests</directory>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/Groups/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\AreaUnit;

class Area
class Area implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Areas.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class Areas
class Areas implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\ContentType;

class Content
class Content implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Coordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class Coordinate
class Coordinate implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class Description
class Description implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\DimensionUnit;

class Dimensions
class Dimensions implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/EpcRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class EpcRating
class EpcRating implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/External.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class External
class External implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/GoogleStreetView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class GoogleStreetView
class GoogleStreetView implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/LeaseExpiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class LeaseExpiry
class LeaseExpiry implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class Location
class Location implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/MinMaxArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mehmetbulut\Zoopla\SynthesizeTrait;

class MinMaxArea
class MinMaxArea implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/MinimumContractLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\RentalTermUnit;

class MinimumContractLength
class MinimumContractLength implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/PafAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\PostCodeType;

class PafAddress
class PafAddress implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/PricePerUnitArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use mehmetbulut\Zoopla\SynthesizeTrait;
use mehmetbulut\Zoopla\Values\AreaUnit;

class PricePerUnitArea
class PricePerUnitArea implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/Pricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use mehmetbulut\Zoopla\Values\PricingRentFrequency;
use mehmetbulut\Zoopla\Values\TransactionType;

class Pricing
class Pricing implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/ServiceCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use mehmetbulut\Zoopla\Values\AreaUnit;
use mehmetbulut\Zoopla\Values\Frequency;

class ServiceCharge
class ServiceCharge implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Groups/TenantEligibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use mehmetbulut\Zoopla\Values\TenantEligibilityDss;
use mehmetbulut\Zoopla\Values\TenantEligibilityStudent;

class TenantEligibility
class TenantEligibility implements \JsonSerializable
{
use SynthesizeTrait;

Expand Down
12 changes: 0 additions & 12 deletions src/Request/RequestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public function getObject()
return json_decode($this->getJson(), false);
}

public function jsonSerialize()
{
$data = [];
foreach ($this->arrSynthesize as $key => $value) {
if (isset($this->{$key}) && !empty($this->{$key})) {
$data[$key] = $this->{$key};
}
}

return $data;
}

public function getUrl($environment)
{
if ($environment == ZooplaRealTime::TEST) {
Expand Down
50 changes: 30 additions & 20 deletions src/SynthesizeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait SynthesizeTrait
{
protected $_data = [];

public function __set($property, $value)
{
if ($this->hasProperty($property)) {
Expand All @@ -15,29 +17,28 @@ public function __set($property, $value)
}
}

public function __isset($property)
{
return isset($this->_data[$property]);
}

public function __get($property)
{
if (property_exists($this, $property)) {
return $this->{$property};
} else if ($this->hasProperty($property)) {
if (is_array($property)) {
return $this->{$property};
} else {
$class = $this->arrSynthesize[$property]['class'];
return $this->{$property} = new $class();
}
if (isset($this->_data[$property])) {
return $this->_data[$property];
}

throw new \Exception('Invalid param', Response::HTTP_BAD_REQUEST);
if (!$this->hasProperty($property)) {
throw new \Exception('Invalid param', Response::HTTP_BAD_REQUEST);
}

$class = $this->arrSynthesize[$property]['class'];
return $this->_data[$property] = new $class();
}

private function hasProperty($property): bool
{
if (isset($this->arrSynthesize[$property])) {
return true;
} else {
return false;
}
return isset($this->arrSynthesize[$property]);
}

private function setProperty($property, $value)
Expand Down Expand Up @@ -82,7 +83,7 @@ private function setProperty($property, $value)
if ($value) {
if (is_string($value)) {
$check = true;
} else if (is_object($value) && $value instanceof $param['class']) {
} else if ($value instanceof $param['class']) {
$check = true;
}
}
Expand All @@ -107,20 +108,29 @@ private function setProperty($property, $value)
case 'date'://Y-m-d
$format = 'Y-m-d';
$d = DateTime::createFromFormat($format, $value);
$check = $d && $d->format($format) == $value;
$check = $d && $d->format($format) === $value;
break;

case 'datetime'://Y-m-d H:i:s
$format = 'Y-m-d H:i:s';
$d = DateTime::createFromFormat($format, $value);
$check = $d && $d->format($format) == $value;
$check = $d && $d->format($format) === $value;
break;
}

if (!$check) {
throw new \Exception('Invalid type '.$property.' '.$param['type'], Response::HTTP_BAD_REQUEST);
} else if ($value) {
$this->{$property} = $value;
}

if (!$value) {
return;
}

$this->_data[$property] = $value;
}

public function jsonSerialize():array
{
return $this->_data;
}
}
1 change: 0 additions & 1 deletion tests/SendPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function testSendPropertyParams()
//location
$request->location->property_number_or_name = 'ds';
$request->location->street_name = 'ds';
$request->location->street_name = 'ds';
$request->location->locality = 'ds';
$request->location->town_or_city = 'ds';
$request->location->county = 'London';
Expand Down

0 comments on commit ac0532a

Please sign in to comment.