Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Php8 (#15)
Browse files Browse the repository at this point in the history
* Allowed PHP 8 or above in composer.json

* initial refactor

* continued refactor
  • Loading branch information
B3none authored Jul 26, 2022
1 parent 03f33ac commit ef98576
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 263 deletions.
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
{
"name": "silktide/prospect-php-client",
"description": "PHP client for integrating Prospect into your projects.",

"require": {
"php": "^7.4",
"php": "^7.4|^8",
"ext-json": "*",
"guzzlehttp/guzzle": "~6.0"
},

"require-dev": {
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^0.12.36",
"symfony/dotenv": "^5.1"
},

"authors": [
{
"name": "Greg Bowler",
"email": "greg.bowler@g105b.com"
},
{
"name": "Alex Blackham",
"email": "alexblackham@silktide.com"
}
],

"autoload": {
"psr-4": {
"Silktide\\ProspectClient\\": "src"
}
},

"autoload-dev": {
"psr-4": {
"Silktide\\ProspectClient\\UnitTest\\": "test/unit"
Expand Down
3 changes: 1 addition & 2 deletions src/Api/ReportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Silktide\ProspectClient\Request\FetchReportRequest;
use Silktide\ProspectClient\Request\ReanalyzeReportRequest;
use Silktide\ProspectClient\Request\SearchReportRequest;
use Silktide\ProspectClient\Entity\Report;
use Silktide\ProspectClient\Http\HttpWrapper;

class ReportApi
Expand Down Expand Up @@ -37,4 +36,4 @@ public function search(): SearchReportRequest
{
return new SearchReportRequest($this->httpWrapper);
}
}
}
31 changes: 11 additions & 20 deletions src/Entity/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ class Report
{
private array $data;

private function __construct()
{
}

public static function create(array $data) : Report
public static function create(array $data): Report
{
$report = new Report();
$report->data = $data;
Expand All @@ -19,22 +15,22 @@ public static function create(array $data) : Report

public function getReportId(): string
{
return $this->data["report_id"];
return $this->data['report_id'];
}

public function getAccountId(): string
{
return $this->data["account_id"];
return $this->data['account_id'];
}

public function getDomain(): string
{
return $this->data["domain"];
return $this->data['domain'];
}

public function getOverallScore(): int
{
return $this->data["overall_score"];
return $this->data['overall_score'];
}

/**
Expand All @@ -43,7 +39,7 @@ public function getOverallScore(): int
*/
public function getReportSection(string $name): ?array
{
if(!is_array($this->data)) {
if (!is_array($this->data)) {
return null;
}

Expand All @@ -52,26 +48,21 @@ public function getReportSection(string $name): ?array

public function getAllReportSections(): array
{
$skipKeys = ["meta"];
$skipKeys = ['meta'];
$sections = $this->data;

$sections = array_filter($sections, function($value, $key)use($skipKeys) {
if(in_array($key, $skipKeys)) {
return false;
}
if(!is_array($value)) {
return array_filter($sections, function($value, $key) use ($skipKeys) {
if (in_array($key, $skipKeys) || !is_array($value)) {
return false;
}

return true;
}, ARRAY_FILTER_USE_BOTH);

return $sections;
}

public function getMetaValue(string $key): ?string
{
return $this->data["meta"][$key] ?? null;
return $this->data['meta'][$key] ?? null;
}

/**
Expand All @@ -82,4 +73,4 @@ public function getValue(string $key)
{
return $this->data[$key] ?? null;
}
}
}
12 changes: 5 additions & 7 deletions src/Entity/ReportCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ class ReportCategory
private float $score;
private array $sections;

private function __construct()
{
}

public static function create(string $label, float $score, array $sections) : ReportCategory
public static function create(string $label, float $score, array $sections): ReportCategory
{
$reportCategory = new ReportCategory();
$reportCategory->label = $label;
Expand All @@ -31,9 +27,11 @@ public function getScore(): float
return $this->score;
}

/** @return string[] */
/**
* @return string[]
*/
public function getSections(): array
{
return $this->sections;
}
}
}
10 changes: 2 additions & 8 deletions src/Entity/ReportPercentile.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Silktide\ProspectClient\Entity;


class ReportPercentile
{
private string $type;
Expand All @@ -14,10 +12,6 @@ class ReportPercentile
private int $count;
private int $percentile;

private function __construct()
{
}

public function getType(): string
{
return $this->type;
Expand Down Expand Up @@ -61,7 +55,7 @@ public static function create(
float $average,
int $count,
int $percentile
) : ReportPercentile
): ReportPercentile
{
$entity = new ReportPercentile();
$entity->type = $type;
Expand All @@ -73,4 +67,4 @@ public static function create(
$entity->percentile = $percentile;
return $entity;
}
}
}
7 changes: 1 addition & 6 deletions src/Exception/Api/InvalidRequestException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php


namespace Silktide\ProspectClient\Exception\Api;


use Silktide\ProspectClient\Exception\ProspectClientException;

class InvalidRequestException extends ProspectClientException
{

}
class InvalidRequestException extends ProspectClientException {}
7 changes: 1 addition & 6 deletions src/Exception/Api/InvalidServerResponseException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php


namespace Silktide\ProspectClient\Exception\Api;


use Silktide\ProspectClient\Exception\ProspectClientException;

class InvalidServerResponseException extends ProspectClientException
{

}
class InvalidServerResponseException extends ProspectClientException {}
28 changes: 3 additions & 25 deletions src/Exception/Api/ReportAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,26 @@

class ReportAlreadyExistsException extends ProspectClientException
{
protected string $reportId;
protected ?string $resolvedUrl;

/**
* @var string
*/
protected $reportId;

/**
* @var string|null
*/
protected $resolvedUrl;

/**
* @return string
*/
public function getReportId(): string
{
return $this->reportId;
}

/**
* @param string $reportId
*/
public function setReportId(string $reportId): void
{
$this->reportId = $reportId;
}

/**
* @return string|null
*/
public function getResolvedUrl(): ?string
{
return $this->resolvedUrl;
}

/**
* @param string|null $resolvedUrl
*/
public function setResolvedUrl(?string $resolvedUrl): void
{
$this->resolvedUrl = $resolvedUrl;
}


}
}
5 changes: 1 addition & 4 deletions src/Exception/Api/ReportNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

use Silktide\ProspectClient\Exception\ProspectClientException;

class ReportNotFoundException extends ProspectClientException
{

}
class ReportNotFoundException extends ProspectClientException {}
6 changes: 2 additions & 4 deletions src/Exception/Api/ReportPathDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php

namespace Silktide\ProspectClient\Exception\Api;

use Silktide\ProspectClient\Exception\ProspectClientException;

class ReportPathDoesNotExistException extends ProspectClientException
{

}
class ReportPathDoesNotExistException extends ProspectClientException {}
5 changes: 1 addition & 4 deletions src/Exception/Api/ReportStillRunningException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

use Silktide\ProspectClient\Exception\ProspectClientException;

class ReportStillRunningException extends ProspectClientException
{

}
class ReportStillRunningException extends ProspectClientException {}
14 changes: 7 additions & 7 deletions src/Exception/Api/ReportUnprocessableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ class ReportUnprocessableException extends ProspectClientException
private ?string $url = null;
private bool $isUrlRecommended = false;

public function setIssue(?string $issue) : void
public function setIssue(?string $issue): void
{
$this->issue = $issue;
}

public function getIssue() : ?string
public function getIssue(): ?string
{
return $this->issue;
}

public function setUrl(string $url) : void
public function setUrl(string $url): void
{
$this->url = $url;
}

public function getUrl() : ?string
public function getUrl(): ?string
{
return $this->url;
}

public function setUrlRecommended(bool $recommended)
public function setUrlRecommended(bool $recommended): void
{
$this->isUrlRecommended = $recommended;
}

public function isUrlRecommended() : bool
public function isUrlRecommended(): bool
{
return $this->isUrlRecommended;
}
}
}
5 changes: 1 addition & 4 deletions src/Exception/ProspectClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

use RuntimeException;

class ProspectClientException extends RuntimeException
{

}
class ProspectClientException extends RuntimeException {}
Loading

0 comments on commit ef98576

Please sign in to comment.