Skip to content
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

Feature/support php8 only #36

Merged
merged 4 commits into from
Sep 12, 2023
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
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"homepage": "https://github.com/JKetelaar/PHP-Kiyoh-API",
"license": "GPL-3.0+",
"require": {
"php": "~7.3 || ^8.0",
"php": "^8.0",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.5"
"guzzlehttp/guzzle": "^6.2 || ^7.0"
},
"require-dev": {
Expand Down
12 changes: 1 addition & 11 deletions src/JKetelaar/Kiyoh/Factory/ReviewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

class ReviewFactory
{
/**
* @param SimpleXMLElement $element
*
* @return Company
*/
public static function createCompany(SimpleXMLElement $element): Company
{
$company = new Company(
Expand All @@ -43,11 +38,6 @@ public static function createCompany(SimpleXMLElement $element): Company
return $company;
}

/**
* @param SimpleXMLElement $element
*
* @return Review
*/
public static function createReview(SimpleXMLElement $element): Review
{
$review = new Review(
Expand All @@ -68,7 +58,7 @@ public static function createReview(SimpleXMLElement $element): Review
/**
* @param SimpleXMLElement $elements
*
* @return array
* @return array<int, ReviewContent>
*/
public static function createReviewContent(SimpleXMLElement $elements): array
{
Expand Down
36 changes: 3 additions & 33 deletions src/JKetelaar/Kiyoh/Kiyoh.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,26 @@ class Kiyoh
{
public const COMPANY_REVIEWS_URL = 'https://www.kiyoh.com/v1/review/feed.xml?hash=%s&limit=%s';

/**
* @var string
*/
private $connectorCode;

/**
* @var Client
*/
private $client;
/**
* @var int
*/
private $reviewCount;
private Client $client;

/**
* Kiyoh constructor.
*
* @param string $connectorCode
* @param int $reviewCount Either a number of reviews to retrieve
* @param int $reviewCount A number of reviews to retrieve
*/
public function __construct(string $connectorCode, int $reviewCount = 10)
public function __construct(private string $connectorCode, private int $reviewCount = 10)
{
$this->client = new Client();
$this->connectorCode = $connectorCode;
$this->reviewCount = $reviewCount;
}

/**
* Gets the 10 latest reviews.
*
* @return Company
*/
public function getCompany(): Company
{
return $this->parseData($this->getContent());
}

/**
* @param string|null $content
*
* @return Model\Company
*/
protected function parseData(?string $content = null): Model\Company
{
if ($content === null) {
Expand All @@ -69,26 +47,18 @@ protected function parseData(?string $content = null): Model\Company
return ReviewFactory::createCompany($content);
}

/**
* @return string
*/
public function getContent(): string
{
return $this->getClient()->request('GET', $this->getCompanyURL())->getBody()->getContents();
}

/**
* @return Client
*/
public function getClient(): Client
{
return $this->client;
}

/**
* Returns parsed Recent Company Reviews URL.
*
* @return string
*/
public function getCompanyURL(): string
{
Expand Down
128 changes: 10 additions & 118 deletions src/JKetelaar/Kiyoh/Model/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,208 +10,102 @@

class Company
{
/**
* @var float
*/
private $averageRating;

/**
* @var int
*/
private $numberReviews;

/**
* @var float
*/
private $last12MonthAverageRating;

/**
* @var int
*/
private $last12MonthNumberReviews;

/**
* @var int
*/
private $percentageRecommendation;

/**
* @var int
*/
private $locationId;

/**
* @var string
*/
private $locationName;

/**
* @var Review[]
*/
private $reviews;
private array $reviews;

/**
* Company constructor.
*
* @param float $averageRating
* @param int $numberReviews
* @param float $last12MonthAverageRating
* @param int $last12MonthNumberReviews
* @param int $percentageRecommendation
* @param int $locationId
* @param string $locationName
*/
public function __construct(
float $averageRating,
int $numberReviews,
float $last12MonthAverageRating,
int $last12MonthNumberReviews,
int $percentageRecommendation,
int $locationId,
string $locationName
private float $averageRating,
private int $numberReviews,
private float $last12MonthAverageRating,
private int $last12MonthNumberReviews,
private int $percentageRecommendation,
private int $locationId,
private string $locationName
) {
$this->averageRating = $averageRating;
$this->numberReviews = $numberReviews;
$this->last12MonthAverageRating = $last12MonthAverageRating;
$this->last12MonthNumberReviews = $last12MonthNumberReviews;
$this->percentageRecommendation = $percentageRecommendation;
$this->locationId = $locationId;
$this->locationName = $locationName;
}

/**
* @return float
*/
public function getAverageRating(): float
{
return $this->averageRating;
}

/**
* @param float $averageRating
*
* @return Company
*/
public function setAverageRating(float $averageRating): self
{
$this->averageRating = $averageRating;

return $this;
}

/**
* @return int
*/
public function getNumberReviews(): int
{
return $this->numberReviews;
}

/**
* @param int $numberReviews
*
* @return Company
*/
public function setNumberReviews(int $numberReviews): self
{
$this->numberReviews = $numberReviews;

return $this;
}

/**
* @return float
*/
public function getLast12MonthAverageRating(): float
{
return $this->last12MonthAverageRating;
}

/**
* @param float $last12MonthAverageRating
*
* @return Company
*/
public function setLast12MonthAverageRating(float $last12MonthAverageRating): self
{
$this->last12MonthAverageRating = $last12MonthAverageRating;

return $this;
}

/**
* @return int
*/
public function getLast12MonthNumberReviews(): int
{
return $this->last12MonthNumberReviews;
}

/**
* @param int $last12MonthNumberReviews
*
* @return Company
*/
public function setLast12MonthNumberReviews(int $last12MonthNumberReviews): self
{
$this->last12MonthNumberReviews = $last12MonthNumberReviews;

return $this;
}

/**
* @return int
*/
public function getPercentageRecommendation(): int
{
return $this->percentageRecommendation;
}

/**
* @param int $percentageRecommendation
*
* @return Company
*/
public function setPercentageRecommendation(int $percentageRecommendation): self
{
$this->percentageRecommendation = $percentageRecommendation;

return $this;
}

/**
* @return int
*/
public function getLocationId(): int
{
return $this->locationId;
}

/**
* @param int $locationId
*
* @return Company
*/
public function setLocationId(int $locationId): self
{
$this->locationId = $locationId;

return $this;
}

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

/**
* @param string $locationName
*
* @return Company
*/
public function setLocationName(string $locationName): self
{
$this->locationName = $locationName;
Expand All @@ -220,17 +114,15 @@ public function setLocationName(string $locationName): self
}

/**
* @return Review[]
* @return array<int, Review>
*/
public function getReviews(): array
{
return $this->reviews;
}

/**
* @param Review[] $reviews
*
* @return Company
* @param array<int, Review> $reviews
*/
public function setReviews(array $reviews): self
{
Expand Down
Loading