Skip to content

Commit

Permalink
feat: Support all PHP ^8.0 versions (#111)
Browse files Browse the repository at this point in the history
* feature: Support php ^8.0

* feature: Support php ^8.0

* feature: Support php ^8.0

* feature: Support php ^8.0

* feature: Support php ^8.0

* feature: Support php ^8.0

* feature: Support php ^8.0
  • Loading branch information
fibble authored Apr 29, 2024
1 parent 32198ba commit d644260
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
security:
uses: dvsa/.github/.github/workflows/php-library-security.yml@main
with:
php-versions: "[\"8.0\"]"
php-versions: "[\"8.0\", \"8.1\", \"8.2\", \"8.3\"]"
secrets:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

Expand All @@ -21,5 +21,5 @@ jobs:
tests:
uses: dvsa/.github/.github/workflows/php-library-tests.yml@main
with:
php-versions: "[\"8.0\"]"
php-versions: "[\"8.0\", \"8.1\", \"8.2\", \"8.3\"]"
fail-fast: false
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function populate(array $transportManagerApplication): static
'markup-' . $this->getTranslationTemplate() . "answer-address",
$address
);
$this->birthDate = (new \DateTime($this->birthDate))->format('d M Y');
if ($this->birthDate && strtotime($this->birthDate) !== false) {
$this->birthDate = (new \DateTime($this->birthDate))->format('d M Y');
}
$this->$addresses = $address;
}

Expand Down
3 changes: 3 additions & 0 deletions Common/src/Common/Filter/StripSpaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class StripSpaces extends AbstractFilter
*/
public function filter($value)
{
if ($value === null) {
return null;
}
return str_replace(' ', '', $value);
}
}
20 changes: 0 additions & 20 deletions Common/src/Common/Form/Elements/Types/Readonly.php

This file was deleted.

9 changes: 9 additions & 0 deletions Common/src/Common/Form/Elements/Types/ReadonlyElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Common\Form\Elements\Types;

use Laminas\Form\Element;

class ReadonlyElement extends Element
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Details
{
/**
* @Form\Options({"label":"lva-tm-details-details-name"})
* @Form\Type("\Common\Form\Elements\Types\Readonly")
* @Form\Type("\Common\Form\Elements\Types\ReadonlyElement")
* @Form\Flags({"priority": -10})
*/
public $name;
Expand Down
20 changes: 18 additions & 2 deletions Common/src/Common/Form/View/Helper/FormDateTimeSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,24 @@ protected function getInputHelper()
*/
protected function getMinutesOptions(string $pattern): array
{
$keyFormatter = new IntlDateFormatter($this->getLocale(), null, null, null, null, 'mm');
$valueFormatter = new IntlDateFormatter($this->getLocale(), null, null, null, null, $pattern);
$keyFormatter = new IntlDateFormatter(
$this->getLocale(),
IntlDateFormatter::NONE,
IntlDateFormatter::SHORT,
null,
IntlDateFormatter::GREGORIAN,
'mm'
);

$valueFormatter = new IntlDateFormatter(
$this->getLocale(),
IntlDateFormatter::NONE,
IntlDateFormatter::SHORT,
null,
IntlDateFormatter::GREGORIAN,
$pattern
);

$date = new DateTime('1970-01-01 00:00:00');

$displayEveryMinute = $this->getDisplayEveryMinute();
Expand Down
7 changes: 4 additions & 3 deletions Common/src/Common/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Laminas\Form\ElementInterface;
use Laminas\Form\LabelAwareInterface;
use Common\Form\Elements\Types\AttachFilesButton;
use Common\Form\Elements\Types\Readonly as ReadonlyElement;
use Common\Form\Elements\Types\ReadonlyElement;

/**
* @see \CommonTest\Form\View\Helper\FormRowTest
Expand Down Expand Up @@ -104,9 +104,10 @@ public function render(ElementInterface $element, ?string $labelPosition = null)
$wrap = false;
}

if (! ($element instanceof Hidden) && $wrap) {
if (!($element instanceof Hidden) && $wrap) {
$classAttribute = $element->getAttribute('class');
$class = $element->getMessages() === [] ? $element->getAttribute('data-container-class') : '';
if (str_starts_with($element->getAttribute('class'), 'govuk-visually-hidden')) {
if ($classAttribute !== null && str_starts_with($classAttribute, 'govuk-visually-hidden')) {
$markup = sprintf(self::$format, 'govuk-visually-hidden', $markup);
} elseif ($element->getOption('render-container') !== false) {
$renderAsFieldset = $element->getOption('render_as_fieldset');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DateBeforeValidator extends AbstractValidator
'dateMustBeBefore' => 'formattedDateMustBeBefore',
];

public string $formattedDateMustBeBefore;

/**
* Create service instance
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IrhpPermitSectorName implements FormatterPluginManagerInterface
*/
public function format($data, $column = [])
{
if (strlen($data['sector']['description']) < 1) {
if (empty($data['sector']['description'])) {
return Escape::html($data['sector']['name']);
}

Expand Down
7 changes: 5 additions & 2 deletions Common/src/Common/Service/Table/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1788,8 +1788,11 @@ private function generatePaginationUrl($data = [], $route = null)

$returnUrl = $url->fromRoute($route, [], $options, true);

// strip out controller and action params - not sure if this is still needed.
$returnUrl = preg_replace('/\/controller\/[a-zA-Z0-9\-_]+\/action\/[a-zA-Z0-9\-_]+/', '', $returnUrl);
if ($returnUrl !== null) {
$returnUrl = preg_replace('/\/controller\/[a-zA-Z0-9\-_]+\/action\/[a-zA-Z0-9\-_]+/', '', $returnUrl);
} else {
$returnUrl = ''; // maintain previous behaviour and reurn empty string when url is null
}

return $returnUrl;
}
Expand Down
1 change: 1 addition & 0 deletions Common/src/Common/Validator/SumCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SumCompare extends AbstractCompare
* @var mixed
*/
protected $sumWith;
private bool $allowEmpty;

/**
* @return $this
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Common library for the OLCS Project",
"type": "library",
"require": {
"php": "~8.0.0",
"php": "^8.0",
"ezyang/htmlpurifier": "^4.17",
"laminas/laminas-authentication": "^2.6",
"laminas/laminas-cache": "^3.0",
Expand All @@ -20,12 +20,12 @@
"laminas/laminas-mvc-plugin-prg": "^1.7",
"laminas/laminas-navigation": "^2.15",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-stdlib": "^3.0",
"laminas/laminas-stdlib": "^3.7",
"laminas/laminas-text": "^2.9",
"laminas/laminas-validator": "^2.11",
"laminas/laminas-view": "^2.23",
"olcs/olcs-logging": "^6.0|^7.0",
"olcs/olcs-transfer": "^7.0.1",
"olcs/olcs-transfer": "^7.1.0",
"olcs/olcs-utils": "^6.0",
"psr/container": "^1.1|^2"
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"phpstan/extension-installer": true
},
"platform": {
"ext-redis": "4.3"
"ext-redis": "6.0"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/Common/src/Common/Form/View/Helper/FormRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function invokeRendersReadonlyElement(): void
// Setup
$this->setUpSut();
$element = $this->setUpElement(
\Common\Form\Elements\Types\Readonly::class,
\Common\Form\Elements\Types\ReadonlyElement::class,
[
'name' => 'readonly',
'label' => 'Foo',
Expand Down
27 changes: 27 additions & 0 deletions test/Common/src/Common/Service/Data/Search/QueryStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace CommonTest\Common\Service\Data\Search;

use ArrayObject;

/**
* Class QueryStub
* @template-extends ArrayObject<array-key, mixed>
*/
class QueryStub extends ArrayObject
{
public $limit;
public $page;

public function __construct(
$limit = null,
$page = null,
$input = [],
$flags = 0,
$iterator_class = "ArrayIterator"
) {
$this->limit = $limit;
$this->page = $page;
parent::__construct($input, $flags, $iterator_class);
}
}
6 changes: 2 additions & 4 deletions test/Common/src/Common/Service/Data/Search/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public function testGetLimit($query, $expected): void
*/
public function provideGetLimit(): array
{
$stubQuery = new \ArrayObject();
$stubQuery->limit = 15;
$stubQuery = new QueryStub(15);

return [
[$stubQuery, 15],
Expand All @@ -92,8 +91,7 @@ public function testGetPage($query, $expected): void
*/
public function provideGetPage(): array
{
$stubQuery = new \ArrayObject();
$stubQuery->page = 3;
$stubQuery = new QueryStub(15, 3);

return [
[$stubQuery, 3],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class DisqualifyUrlTest extends MockeryTestCase

protected function setUp(): void
{
// Upstream wont fix this, so we need to suppress the deprecation - https://github.com/laminas/laminas-stdlib/issues/85
set_error_handler(function ($severity, $message, $file, $line) {
if (strpos($message, 'Serializable') !== false) {
return true;
}
return false;
}, E_DEPRECATED);

$this->urlHelper = m::mock(UrlHelperService::class);
$this->router = m::mock(TreeRouteStack::class);
$this->request = m::mock(Request::class);
Expand Down
11 changes: 11 additions & 0 deletions test/Common/src/Common/Util/RestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class RestClientTest extends m\Adapter\Phpunit\MockeryTestCase
'checkForUnexpectedResponseCode'
];

public function setUp(): void
{
// Upstream wont fix this, so we need to suppress the deprecation - https://github.com/laminas/laminas-stdlib/issues/85
set_error_handler(function ($severity, $message, $file, $line) {
if (strpos($message, 'Serializable') !== false) {
return true;
}
return false;
}, E_DEPRECATED);
}

public function getSutMock(array|null $methods = null): RestClient
{
if ($methods === null) {
Expand Down

0 comments on commit d644260

Please sign in to comment.