Skip to content

Commit d37db93

Browse files
committed
DRD-3201 Upgrade code to work with recent php version
1 parent 8254d43 commit d37db93

16 files changed

Lines changed: 1185 additions & 1121 deletions

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM php:latest
2+
3+
RUN apt-get update && apt-get install -y \
4+
libfreetype6-dev \
5+
libjpeg62-turbo-dev \
6+
libpng-dev \
7+
zlib1g-dev \
8+
unzip \
9+
git \
10+
zip \
11+
libmagickwand-dev --no-install-recommends \
12+
&& pecl install imagick \
13+
&& docker-php-ext-enable imagick \
14+
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
15+
&& docker-php-ext-install gd pdo pdo_mysql \
16+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
17+
18+
WORKDIR /app
19+
20+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
21+
COPY . .
22+
23+
RUN composer install
24+
25+
CMD ["vendor/bin/phpunit"]
26+

composer.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "timeoutdigital/image-transform",
33
"type": "library",
4-
"version": "master",
4+
"version": "1.0.0",
55
"description": "Image Transform",
66
"keywords": ["image"],
77
"homepage": "http://timeout.com",
@@ -13,15 +13,20 @@
1313
"email": "contact@timeout.com"
1414
}
1515
],
16-
1716
"require": {
18-
"php": ">=5.3.2"
17+
"php": "^8.1"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^10"
1921
},
20-
2122
"autoload": {
22-
"psr-0": {
23-
"ImageTransform": "src/"
23+
"psr-4": {
24+
"ImageTransform\\": "src/"
25+
}
26+
},
27+
"config": {
28+
"platform": {
29+
"php": "8.2.0"
2430
}
25-
}
31+
}
2632
}
27-

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
php:
3+
build: .
4+
volumes:
5+
- .:/app
6+
working_dir: /app
7+
command: sh -c "composer install && vendor/bin/phpunit"

phpunit.xml.dist

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="true"
5-
bootstrap="src/autoload.php"
6-
colors="false"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false"
12-
syntaxCheck="true"
13-
verbose="true"
14-
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
15-
strict="true">
16-
2+
<phpunit
3+
bootstrap="src/autoload.php"
4+
colors="true"
5+
stopOnFailure="false"
6+
cacheResultFile=".phpunit.cache"
7+
executionOrder="depends,defects"
8+
>
179
<testsuites>
1810
<testsuite name="ImageTransform Test Suite">
19-
<directory>./tests/ImageTransform</directory>
11+
<directory suffix="Test.php">./tests/ImageTransform</directory>
2012
</testsuite>
2113
</testsuites>
22-
23-
<filter>
24-
<whitelist addUncoveredFilesFromWhitelist="true">
25-
<directory suffix=".php">./src/ImageTransform</directory>
26-
</whitelist>
27-
</filter>
28-
29-
<logging>
30-
<log type="coverage-html" target="build/coverage" title="ImageTransform"
31-
charset="UTF-8" yui="true" highlight="true"
32-
lowUpperBound="35" highLowerBound="70"/>
33-
<log type="coverage-clover" target="build/logs/clover.xml"/>
34-
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
35-
</logging>
3614
</phpunit>

src/ImageTransform/FileAccessAdapter.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@
1616
*/
1717
interface FileAccessAdapter
1818
{
19-
/**
20-
* Create an image resource
21-
*
22-
* @param integer $width Width of the image to be created
23-
* @param integer $height Height of the image to be created
24-
*/
25-
public function create($width, $height);
19+
/**
20+
* Create an image resource
21+
*
22+
* @param integer $width Width of the image to be created
23+
* @param integer $height Height of the image to be created
24+
*/
25+
public function create($width, $height);
2626

27-
/**
28-
* Open a resource for an Image
29-
*
30-
* @param string $filepath Location of the file to open
31-
*/
32-
public function open($filepath);
27+
/**
28+
* Open a resource for an Image
29+
*
30+
* @param string $filepath Location of the file to open
31+
*/
32+
public function open($filepath);
3333

34-
/**
35-
* Flush an Image resource to stdout
36-
*
37-
* @param string $mimeType Mime type of the target file
38-
*/
39-
public function flush($mimeType = false);
34+
/**
35+
* Flush an Image resource to stdout
36+
*
37+
* @param string $mimeType Mime type of the target file
38+
*/
39+
public function flush($mimeType = false);
4040

41-
/**
42-
* Save an Image resource under its current location
43-
*/
44-
public function save();
41+
/**
42+
* Save an Image resource under its current location
43+
*/
44+
public function save();
4545

46-
/**
47-
* Save an Image resource under a given filepath
48-
*
49-
* @param string $filepath Locastion where to save the resource
50-
* @param string $mimeType Mime type of the target file
51-
*/
52-
public function saveAs($filepath, $mimeType = false);
46+
/**
47+
* Save an Image resource under a given filepath
48+
*
49+
* @param string $filepath Locastion where to save the resource
50+
* @param string $mimeType Mime type of the target file
51+
*/
52+
public function saveAs($filepath, $mimeType = false);
5353
}

src/ImageTransform/Image.php

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,49 @@
1818
*/
1919
abstract class Image
2020
{
21-
/**
22-
* @var array $attributes Key / value store to be used for meta information by delegates.
23-
*/
24-
protected $attributes = array();
21+
/**
22+
* @var array $attributes Key / value store to be used for meta information by delegates.
23+
*/
24+
protected array $attributes = [];
2525

26-
/**
27-
* C'tor
28-
*
29-
* @param array $classNames List of Delegate inheriting classes providing transformations.
30-
*/
31-
public function __construct($filepath = false)
32-
{
33-
$this->initialize();
34-
35-
if(false !== $filepath)
26+
/**
27+
* @param bool $filepath
28+
*/
29+
public function __construct($filepath = false)
3630
{
37-
$this->open($filepath);
31+
$this->initialize();
32+
33+
if (false !== $filepath) {
34+
$this->open($filepath);
35+
}
3836
}
39-
}
4037

41-
/**
42-
* Initializes image-api specific code
43-
*/
44-
abstract protected function initialize();
38+
/**
39+
* Initializes image-api specific code
40+
*/
41+
abstract protected function initialize();
4542

46-
/**
47-
* Attribute accessor.
48-
*
49-
* @param string $key Name of the attribute to return
50-
* @param array $default Default value in case the key is unknown
51-
* @return mixed The value as stored in $this->attributes[$key] or the $default
52-
*/
53-
public function get($key, $default = false)
54-
{
55-
return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default;
56-
}
43+
/**
44+
* Attribute accessor.
45+
*
46+
* @param string $key Name of the attribute to return
47+
* @param bool|array $default Default value in case the key is unknown
48+
* @return mixed The value as stored in $this->attributes[$key] or the $default
49+
*/
50+
public function get(string $key, bool|array $default = false): mixed
51+
{
52+
return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default;
53+
}
5754

58-
/**
59-
* Attribute mutator.
60-
w
61-
*
62-
* @param string $key Name of the attribute to set
63-
* @param array $value Value to be set
64-
*/
65-
public function set($key, $value)
66-
{
67-
$this->attributes[$key] = $value;
68-
}
55+
/**
56+
* Attribute mutator.
57+
* w
58+
*
59+
* @param string $key Name of the attribute to set
60+
* @param array $value Value to be set
61+
*/
62+
public function set($key, $value): void
63+
{
64+
$this->attributes[$key] = $value;
65+
}
6966
}

0 commit comments

Comments
 (0)