Skip to content

Commit c651993

Browse files
lacatoirelacatoire
andauthored
Add explicit type declarations to class constants (PHP 8.3+) (#215)
### Motivation - Enhances type safety and static analysis. - Makes code intent clearer. - Prepares PhD for PHP 8.4 compatibility and future strictness. ### Scope - Added types such as `int`, `string`, `bool`, or `array` to class constants. - Example: Before: `public const FORMAT_HTML = 1;` `public const NAME = 'PhD';` After: `public const int FORMAT_HTML = 1;` `public const string NAME = 'PhD';` ### Impact - ✅ No runtime behavior change. - ✅ Fully backward compatible with PHP 8.3+. - ⚙️ Code clarity and safety improvement only. - Updated `composer.json` to indicate PHP 8.3 requirement - Removed 8.1 and 8.2 CI pipelines ### References - [PHP 8.3: Typed class constants RFC](https://wiki.php.net/rfc/typed_class_constants) - [PHP manual: Class constants](https://www.php.net/manual/en/language.oop5.constants.php) --------- Co-authored-by: lacatoire <louis-arnaud.catoire@external.drivalia.com>
1 parent 5f10df1 commit c651993

File tree

15 files changed

+32
-32
lines changed

15 files changed

+32
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
ubuntu:
55
strategy:
66
matrix:
7-
version: ['8.1', '8.2', '8.3', '8.4', '8.5']
7+
version: ['8.3', '8.4', '8.5']
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout PhD

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
name: test
66
strategy:
77
matrix:
8-
version: ['8.1', '8.2', '8.3', '8.4', '8.5']
8+
version: ['8.3', '8.4', '8.5']
99
continue-on-error: ${{ matrix.version == '8.5' }}
1010
runs-on: ubuntu-latest
1111
steps:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=8.1.0",
21+
"php": ">=8.3",
2222
"ext-dom": "*",
2323
"ext-sqlite3": "*",
2424
"ext-xmlreader": "*"

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpdotnet/phd/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Config
55
{
6-
public const VERSION = '@phd_version@';
6+
public const string VERSION = '@phd_version@';
77
public readonly string $copyright;
88

99
/** @var array<string, string> */

phpdotnet/phd/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class ErrorHandler
55
{
6-
private const ERROR_MAP = [
6+
private const array ERROR_MAP = [
77
// PHP Triggered Errors
88
E_DEPRECATED => 'E_DEPRECATED ',
99
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR ',

phpdotnet/phd/Format.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class Format extends ObjectStorage
1010
* @var integer
1111
* @usedby createLink()
1212
*/
13-
const SDESC = 1;
13+
const int SDESC = 1;
1414

1515
/**
1616
* Represents a long description.
@@ -19,7 +19,7 @@ abstract class Format extends ObjectStorage
1919
* @var integer
2020
* @usedby createLink()
2121
*/
22-
const LDESC = 2;
22+
const int LDESC = 2;
2323

2424
protected Config $config;
2525
protected OutputHandler $outputHandler;

phpdotnet/phd/OutputHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class OutputHandler
55
{
66
/** @var array */
7-
private const CONSTANT_TO_MESSAGE_CATEGORY_MAP = [
7+
private const array CONSTANT_TO_MESSAGE_CATEGORY_MAP = [
88
// PhD informationals
99
VERBOSE_INDEXING => 'Indexing ',
1010
VERBOSE_FORMAT_RENDERING => 'Rendering Format ',

phpdotnet/phd/Package/Generic/Manpage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace phpdotnet\phd;
33

44
class Package_Generic_Manpage extends Format_Abstract_Manpage {
5-
const OPEN_CHUNK = 0x01;
6-
const CLOSE_CHUNK = 0x02;
5+
const int OPEN_CHUNK = 0x01;
6+
const int CLOSE_CHUNK = 0x02;
77

88
private $elementmap = array( /* {{{ */
99
'acronym' => 'format_suppressed_tags',

phpdotnet/phd/Package/IDE/API.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class Package_IDE_API
3535
*
3636
* @var string
3737
*/
38-
const FUNCTIONS_DIR = 'ide-xml';
38+
const string FUNCTIONS_DIR = 'ide-xml';
3939

4040
/**
4141
* Output file of the funclist format in the IDE Package.
4242
*
4343
* @var string
4444
*/
45-
const FUNCLIST_FILE = 'ide-funclist.txt';
45+
const string FUNCLIST_FILE = 'ide-funclist.txt';
4646

4747
/**
4848
* PhD output directory.

0 commit comments

Comments
 (0)