You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modernize codebase to PHP 8.2+ with strict types and CI matrix (#190)
- Require PHP ^8.2; upgrade PHPUnit to ^10.5 || ^11.0
- Replace the PHP 7.4 CI job with an 8.2-8.5 matrix using per-version Composer cache keys
- Enforce declare(strict_types=1) and PSR-12 across the codebase; convert legacy switch statements to match expressions; remove dead code
- Fix latent float-division bugs with intdiv() in DecimalToBinary, DecimalToOctal, DecimalToHex, RailfenceCipher, MergeSort, and HeapSort
- ArrayHelpers: throw new \UnexpectedValueException() (previously an undefined-constant fatal) and fix the sortedness check (&& to ||)
- median(): declare float|int return type and reject non-numeric input (behavior change: previously returned a meaningless value, now throws)
- Stack::search(): return int|false, mirroring array_search()
- Queue::toString() and maxCharacter(): cast to string to preserve behavior under strict types
- Add regression tests for each fix; suite green on PHP 8.2-8.5 (285 tests, 4856 assertions)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+20-17Lines changed: 20 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,31 +28,33 @@ Please help us keep our issue list small by adding fixes: #{$ISSUE_NO} to the co
28
28
#### What is an Algorithm?
29
29
30
30
An Algorithm is one or more functions (or classes) that:
31
-
* take one or more inputs,
32
-
* perform some internal calculations or data manipulations,
33
-
* return one or more outputs,
34
-
* have minimal side effects (Ex. print(), plot(), read(), write()).
31
+
32
+
- take one or more inputs,
33
+
- perform some internal calculations or data manipulations,
34
+
- return one or more outputs,
35
+
- have minimal side effects (Ex. print(), plot(), read(), write()).
35
36
36
37
Algorithms should be packaged in a way that would make it easy for readers to put them into larger programs.
37
38
38
39
Algorithms should:
39
-
* have intuitive class and function names that make their purpose clear to readers
40
-
* use PHP naming conventions and intuitive variable names to ease comprehension
41
-
* be flexible to take different input values
42
-
* have PHP type hints for their input parameters and return values
43
-
* raise PHP exceptions (UnexpectedValueException, etc.) on erroneous input values
44
-
* have docstrings with clear explanations and/or URLs to source materials
45
-
* contain doctests that test both valid and erroneous input values
46
-
* return all calculation results instead of printing or plotting them
40
+
41
+
- have intuitive class and function names that make their purpose clear to readers
42
+
- use PHP naming conventions and intuitive variable names to ease comprehension
43
+
- be flexible to take different input values
44
+
- have PHP type hints for their input parameters and return values
45
+
- raise PHP exceptions (UnexpectedValueException, etc.) on erroneous input values
46
+
- have docstrings with clear explanations and/or URLs to source materials
47
+
- contain doctests that test both valid and erroneous input values
48
+
- return all calculation results instead of printing or plotting them
47
49
48
50
Algorithms in this repo should not be how-to examples for existing PHP packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing PHP packages but each algorithm in this repo should add unique value.
49
51
50
52
#### Coding Style
51
53
52
54
We want your work to be readable by others; therefore, we encourage you to note the following:
53
55
54
-
- Please write in PHP 7.1+
55
-
- Please put thought into naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments
56
+
- Please write in PHP 8.2+
57
+
- Please put thought into naming of functions, classes, and variables. Help your reader by using **descriptive names** that can help you to remove redundant comments
56
58
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines
57
59
- Please follow the [PHP Basic Coding Standard](https://www.php-fig.org/psr/psr-12/) style guide. So functionNames should be camelCase, CONSTANTS in UPPER_CASE, Name\Spaces and ClassNames should follow an "autoloading" PSR, etc.
58
60
@@ -66,13 +68,14 @@ We want your work to be readable by others; therefore, we encourage you to note
66
68
67
69
- Avoid importing external libraries for basic algorithms. Only use them for complicated algorithms
68
70
69
-
- Ensure code is linted with phpcs, and passing all linting checks (vendor/bin/phpcs -n)
71
+
- Ensure code is strictly typed and passes the repository test suite (`composer run-script test`)
72
+
- Ensure code is properly linted and formatted (`vendor/bin/phpcs -n`)
70
73
71
74
#### Other Standard While Submitting Your Work
72
75
73
-
- File extension for code should be `.php`
76
+
- File extension for code should be `.php`
74
77
- After adding a new File/Directory, please make sure to update the [DIRECTORY.md](DIRECTORY.md) file with the details.
75
-
- If possible, follow the standard *within* the folder you are submitting to
78
+
- If possible, follow the standard _within_ the folder you are submitting to
76
79
- If you have modified/added code work, make sure the code compiles before submitting
77
80
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors
78
81
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
0 commit comments