Skip to content

Commit

Permalink
Switch to PHP 8.2 (#3733)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlazerMann authored Dec 6, 2023
1 parent 7fda3af commit 7d66bb2
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
ini-values: pcov.directory=.
coverage: pcov

Expand All @@ -44,7 +44,7 @@ jobs:
run: composer install --prefer-dist -vvv --no-progress

- name: PHP psalm Taint
run: php ./vendor/bin/psalm --taint-analysis --php-version='7.4'
run: php ./vendor/bin/psalm --taint-analysis --php-version='8.2'

- name: PHP Design Security
run: ./vendor/bin/progpilot --configuration progpilot.yml html_headers.php category.php generate_template.php gitpull.php linked_pages.php process_page.php authenticate.php
4 changes: 2 additions & 2 deletions .github/workflows/php-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
ini-values: pcov.directory=.
coverage: pcov

Expand All @@ -47,4 +47,4 @@ jobs:
run: ./vendor/bin/phplint --exclude=vendor --no-interaction --no-configuration -vv ./

- name: PHP psalm
run: php ./vendor/bin/psalm --php-version='7.4'
run: php ./vendor/bin/psalm --php-version='8.2'
6 changes: 3 additions & 3 deletions .github/workflows/php-static2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
ini-values: pcov.directory=.
coverage: pcov

Expand All @@ -37,7 +37,7 @@ jobs:
${{ runner.os }}-php-
- name: Configure composer and dependencies
run: composer config allow-plugins.third-party/required-plugin true && composer config minimum-stability dev && composer config prefer-stable true && composer require mediawiki/oauthclient:2.0.0 && composer require phpstan/phpstan phan/phan:3.2.4
run: composer config allow-plugins.third-party/required-plugin true && composer config minimum-stability dev && composer config prefer-stable true && composer require mediawiki/oauthclient:2.0.0 && composer require phpstan/phpstan phan/phan

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
Expand All @@ -47,5 +47,5 @@ jobs:
run: php ./vendor/bin/phpstan --no-interaction analyse --memory-limit=2G constants/*.php html_headers.php Parameter.php user_messages.php constants.php big_jobs.php setup.php expandFns.php Zotero.php apiFunctions.php NameTools.php Comment.php Page.php WikipediaBot.php Template.php category.php generate_template.php linked_pages.php process_page.php authenticate.php

- name: PHP phan
run: php ./vendor/bin/phan --analyze-twice --allow-polyfill-parser --target-php-version='7.4' --minimum-target-php-version='7.4'
run: php ./vendor/bin/phan --analyze-twice --allow-polyfill-parser --target-php-version='8.2' --minimum-target-php-version='8.2'

2 changes: 1 addition & 1 deletion .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
ini-values: pcov.directory=.
coverage: pcov

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
ini-values: pcov.directory=.
coverage: pcov

Expand All @@ -37,7 +37,7 @@ jobs:
${{ runner.os }}-php-
- name: Configure composer and dependencies
run: composer config allow-plugins.third-party/required-plugin true && composer config minimum-stability dev && composer config prefer-stable true && composer require mediawiki/oauthclient:2.0.0 phpunit/phpunit
run: composer config allow-plugins.third-party/required-plugin true && composer config minimum-stability dev && composer config prefer-stable true && composer require mediawiki/oauthclient:2.0.0 phpunit/phpunit:9.*.*

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![codecov](https://codecov.io/gh/ms609/citation-bot/branch/master/graph/badge.svg)](https://codecov.io/gh/ms609/citation-bot)
[![Project Status: Inactive - The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![PHP ](https://img.shields.io/badge/PHP-7.4-blue.svg)](https://www.php.net)
[![PHP ](https://img.shields.io/badge/PHP-8.2-blue.svg)](https://www.php.net)
[![GitHub issues](https://img.shields.io/github/issues/ms609/citation-bot.png)](https://github.com/ms609/citation-bot/issues)


Expand Down Expand Up @@ -71,7 +71,7 @@ Also beware the difference between `else if` and `elseif`.

## Deployment

The bot requires PHP >= 7.4.
The bot requires PHP >= 8.2.

To run the bot from a new environment, you will need to create an `env.php` file (if one doesn't already exist) that sets the needed authentication tokens as environment variables. To do this, you can rename `env.php.example` to `env.php`, set the variables in the file, and then make sure the file is not world readable or writable:

Expand All @@ -81,11 +81,11 @@ To run the bot from a new environment, you will need to create an `env.php` file

become citations[-dev]
webservice stop
webservice --backend=kubernetes php7.4 start
webservice --backend=kubernetes php8.2 start

Or for testing in the shell:

webservice --backend=kubernetes php7.4 shell
webservice --backend=kubernetes php8.2 shell

Before entering the k8s shell, it may be necessary to install phpunit (as wget is not available in the k8s shell).

Expand All @@ -94,7 +94,7 @@ In order to run on the command line one needs OAuth tokens as documented in `env

/usr/bin/php ./process_page.php "Covid Watch|Water|COVID-19_apps" --slow --savetofiles

The command line tool will also accept `page_list.txt` and `page_list2.txt` as page names. In those cases the bot expect a file of such name to contain a single line of | seperated page names. This code requires PHP 7.4 with optional packages included: php74-mbstring php74-sockets php74-opcache php74-openssl php74-xmlrpc php74-gettext php74-curl php74-intl php74-iconv
The command line tool will also accept `page_list.txt` and `page_list2.txt` as page names. In those cases the bot expect a file of such name to contain a single line of | seperated page names. This code requires PHP 8.2 with optional packages included: php82-mbstring php82-sockets php82-opcache php82-openssl php82-xmlrpc php82-gettext php82-curl php82-intl php82-iconv

Command line parameters:
* `--slow` - retrieve bibcodes and expand urls
Expand Down
3 changes: 1 addition & 2 deletions WikipediaBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ final class WikipediaBot {
private Consumer $user_consumer;
private Client $user_client;
private Token $user_token;
/** @var resource $ch */
private static $ch; // All wikipedia connections share a session
private static CurlHandle $ch; // All wikipedia connections share a session
private static bool $init_done = FALSE;
private string $the_user = '';
private static ?self $last_WikipediaBot; // For NonStandardMode()
Expand Down
9 changes: 1 addition & 8 deletions Zotero.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ final class Zotero {
private const ZOTERO_SKIPS = 100;
private const ERROR_DONE = 'ERROR_DONE';
protected static int $zotero_announced = 0;
/**
* @var resource $zotero_ch
* @var resource $ch_ieee
* @var resource $ch_jstor
* @var resource $ch_dx
* @var resource $ch_pmc
**/
protected static $zotero_ch, $ch_ieee, $ch_jstor, $ch_dx, $ch_pmc;
protected static CurlHandle $zotero_ch, $ch_ieee, $ch_jstor, $ch_dx, $ch_pmc;
protected static int $zotero_failures_count = 0;
private static bool $is_setup = FALSE;

Expand Down
4 changes: 2 additions & 2 deletions apiFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,8 @@ function expand_templates_from_archives(array &$templates) : void { // This is d
}
curl_close($ch);
}
/** @param resource $ch **/
function Bibcode_Response_Processing(string $return, $ch, string $adsabs_url) : object {

function Bibcode_Response_Processing(string $return, CurlHandle $ch, string $adsabs_url) : object {
try {
if ($return === "") {
// @codeCoverageIgnoreStart
Expand Down
2 changes: 1 addition & 1 deletion constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
const CROSSREFUSERNAME = '[email protected]';
const PUBMEDUSERNAME = '[email protected]';

const GET_THE_HEADERS = 1; // expects 1 in early PHP, and TRUE in newer versions
const GET_THE_HEADERS = TRUE; // expects 1 in early PHP, and TRUE in newer versions

const BOT_USER_AGENT = "Mozilla/5.0 (compatible; Citation_bot; mailto:[email protected]; +https://citations.toolforge.org/)";

Expand Down
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ to test.
All code is run through several tests. The primary test is a suite of example pages and citation templates. There are a variety of static code analysis tests that look for common errors.
The security tainted data tests make sure that all "untrusted input" (data from wikipedia pages) is output wrapped with the echoable() function: this is not done primarily for security, but for proper output formatting.
The GitHub provided CodeQL test suite is also enabled, but that just checks the one JavaScript file.
Because files over 384K are not indexed by GitHub, there is a test to check for large files: the test will suggest LFS on failure, but do not do that. Template.php is currently the only file at risk.
Because files over 384K are not indexed by GitHub, there is a test to check for large files: the test will suggest LFS on failure, but do not do that. Template.php is currently the only file failing.

## Submitting changes

Expand All @@ -36,7 +36,7 @@ Always write a clear log message for your commits. One-line messages are fine fo
* We prefer `===` and `!==` to `==` and `!=`
* We prefer `curl` to `file_get_contents` for easier debugging and greater control
* We use `echo` and `exit` for normal code, and `print` and `die` for debug code that is intended to be removed later
* All code must be valid PHP 7.4
* All code must be valid PHP 8.2
* Directly comparing strings to integer with comparision operators is different in PHP 7 and 8, so they should not be used
* We want 100% code coverage with untestable code flagged in the source -- such as code that handles error conditions. See the file apiFunctions.php for lots of examples of non-coverage code.
* All curl_init() calls must also set CURLOPT_TIMEOUT to something reasonable for the importance of the data and the speed of the website
Expand Down

0 comments on commit 7d66bb2

Please sign in to comment.