Skip to content

Commit

Permalink
New major version for PHP 8.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Nov 5, 2023
1 parent 06c94a9 commit 9d71dec
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 599 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
php-version: ["8.0", "8.1", "8.2"]
experimental: [false]
os: [ubuntu-latest]
coverage-extension: [pcov]
include:
#- { php-version: '5.3', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
#- { php-version: '5.4', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '5.5', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '5.6', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '7.1', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
steps:
- uses: actions/checkout@v4
- name: Use php ${{ matrix.php-version }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
**/.vagrant
**/auth.json
**/nbproject
**/temp.php
**/test.php
.phpdoc
.phpunit.cache
.phpunit.result.cache
composer.lock
ecs.php
phpunit.xml
rector.php
target
vendor
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ All artifacts are generated in the target directory.

Examples are located in the `example` directory.

Start a development server (requires PHP 5.4) using the command:
Start a development server (requires PHP 8.0+) using the command:

```
make server
Expand All @@ -78,15 +78,15 @@ Create a composer.json in your projects root-directory:
```json
{
"require": {
"tecnickcom/tc-lib-file": "^1.6"
"tecnickcom/tc-lib-file": "^2.0"
}
}
```

Or add to an existing project with:

```bash
composer require tecnickcom/tc-lib-file ^1.6
composer require tecnickcom/tc-lib-file ^2.0
```

## Packaging
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.39
2.0.6
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
}
],
"require": {
"php": ">=5.4",
"php": ">=8.0",
"ext-curl": "*",
"ext-pcre": "*"
},
"require-dev": {
"pdepend/pdepend": "2.13.0",
"phpmd/phpmd": "2.13.0",
"phpunit/phpunit": "10.1.2 || 9.6.7 || 8.5.31 || 7.5.20 || 6.5.14 || 5.7.27 || 4.8.36",
"squizlabs/php_codesniffer": "3.7.2 || 2.9.2"
"phpunit/phpunit": "10.1.2 || 9.6.13",
"squizlabs/php_codesniffer": "3.7.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: max
paths:
- src
- test
Expand Down
2 changes: 1 addition & 1 deletion resources/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git
Package: ~#PKGNAME#~
Provides: php-~#PROJECT#~
Architecture: all
Depends: php (>= 5.4.0), php-curl, ${misc:Depends}
Depends: php (>= 8.0.0), php-curl, ${misc:Depends}
Description: PHP Color library
This library includes PHP classes to read byte-level data from files
2 changes: 1 addition & 1 deletion resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ URL: https://github.com/%{gh_owner}/%{gh_project}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
BuildArch: noarch

Requires: php(language) >= 5.4.0
Requires: php(language) >= 8.0.0
Requires: php-curl
Requires: php-pcre

Expand Down
73 changes: 33 additions & 40 deletions src/Byte.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Byte.php
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <[email protected]>
* @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <[email protected]>
* @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*
* This file is part of tc-lib-file software library.
*/
Expand All @@ -21,31 +21,27 @@
*
* Function to read byte-level data
*
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <[email protected]>
* @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
* @since 2015-07-28
* @category Library
* @package File
* @author Nicola Asuni <[email protected]>
* @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-file
*/
class Byte
{
/**
* String to process
*
* @var string
*/
protected $str = '';

/**
* Initialize a new string to be processed
*
* @param string $str String from where to extract values
*/
public function __construct($str)
{
$this->str = $str;
public function __construct(
/**
* String to process
*/
protected string $str
) {
}

/**
Expand All @@ -54,12 +50,11 @@ public function __construct($str)
* @param int $offset Point from where to read the data.
*
* @return int 8 bit value
*
*/
public function getByte($offset)
public function getByte(int $offset): int
{
$val = unpack('Ci', substr($this->str, $offset, 1));
return $val['i'];
return $val === false ? 0 : $val['i'];
}

/**
Expand All @@ -69,10 +64,10 @@ public function getByte($offset)
*
* @return int 32 bit value
*/
public function getULong($offset)
public function getULong(int $offset): int
{
$val = unpack('Ni', substr($this->str, $offset, 4));
return $val['i'];
return $val === false ? 0 : $val['i'];
}

/**
Expand All @@ -82,10 +77,10 @@ public function getULong($offset)
*
* @return int 16 bit value
*/
public function getUShort($offset)
public function getUShort(int $offset): int
{
$val = unpack('ni', substr($this->str, $offset, 2));
return $val['i'];
return $val === false ? 0 : $val['i'];
}

/**
Expand All @@ -95,10 +90,10 @@ public function getUShort($offset)
*
* @return int 16 bit value
*/
public function getShort($offset)
public function getShort(int $offset): int
{
$val = unpack('si', substr($this->str, $offset, 2));
return $val['i'];
return $val === false ? 0 : $val['i'];
}

/**
Expand All @@ -108,7 +103,7 @@ public function getShort($offset)
*
* @return int 16 bit value
*/
public function getUFWord($offset)
public function getUFWord(int $offset): int
{
return $this->getUShort($offset);
}
Expand All @@ -120,26 +115,24 @@ public function getUFWord($offset)
*
* @return int 16 bit value
*/
public function getFWord($offset)
public function getFWord(int $offset): int
{
$val = $this->getUShort($offset);
if ($val > 0x7fff) {
$val -= 0x10000;
}

return $val;
}

/**
* Get FIXED from string (32-bit signed fixed-point number (16.16).
*
* @param int $offset Point from where to read the data.
*
* @return float
*
*/
public function getFixed($offset)
public function getFixed(int $offset): float
{
// mantissa.fraction
return (float)($this->getFWord($offset) . '.' . $this->getUShort($offset + 2));
return (float) ($this->getFWord($offset) . '.' . $this->getUShort($offset + 2));
}
}
Loading

0 comments on commit 9d71dec

Please sign in to comment.