Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create script to check PHP for syntac compatibility #1931

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions .github/actions/deploy/create-version.sh

This file was deleted.

5 changes: 5 additions & 0 deletions .github/actions/php-linter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM php:7.4

COPY tester.sh /tester.sh

CMD ["/tester.sh", "/work"]
25 changes: 25 additions & 0 deletions .github/actions/php-linter/tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

cd "$1"

ret=0

while IFS= read -d '' file
do
php -l "$file" > /tmp/msg
retSingle=$?

if [ $retSingle -eq 0 ]
then
cat /tmp/msg | sed 's@^@::debug::@'
else
ret=1
msg="$(cat /tmp/msg)"
echo "$msg" | sed 's@^\s*$@@' | grep -v '^$' > /tmp/msg
line=$(cat /tmp/msg | grep -o ' on line [0-9]*' | sed -E 's@ on line ([0-9]*)$@\1@')
prefix="::error file=$file,line=$line,title=PHP linter failed::"
sed "s@^@$prefix@" /tmp/msg
fi
done < <(find lib -type f -name '*.php' -print0)

exit $ret
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-22.04
if: github.event.ref == 'refs/heads/master'
if: github.event.ref == 'refs/heads/master' && github.repository == 'nextcloud/cookbook'
needs: build
steps:
- name: Deploy to GitHub Pages
Expand Down
29 changes: 26 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ jobs:

source-package:
name: Create source code artifacts
needs:
- unit-tests
- code-lint
runs-on: ubuntu-22.04

steps:
Expand Down Expand Up @@ -443,4 +440,30 @@ jobs:
path: ${{ github.event_path }}
retention-days: 1

lint-php:
name: "Lint PHP files to be compatible"
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- name: Checkout of the app
uses: actions/checkout@v4
- name: build docker container image
run: docker build -t php-lint-tester .github/actions/php-linter
- name: Check the code base
run: docker run --rm -v $(pwd):/work:ro php-lint-tester

successful_run:
name: The tests have successfully run
runs-on: ubuntu-22.04
needs:
- unit-tests
- code-lint
- source-package
- lint-php
- event_file
steps:
- name: Run successfully
shell: bash
run: echo "The tests have been running successfully"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Maintenance
- Add PHP lint checker to ensure valid (legacy) PHP syntax
[#1931](https://github.com/nextcloud/cookbook/pull/1931) @christianlupus


## 0.10.3 - 2023-12-04

Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/Filter/JSON/AbstractJSONFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract public function apply(array &$json): bool;
/**
* @param string|int|float|array $value
*/
protected function setJSONValue(array &$json, string $key, string|int|float|array $value): bool {
protected function setJSONValue(array &$json, string $key, $value): bool {
if (!array_key_exists($key, $json)) {
$json[$key] = $value;
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/Filter/Output/RecipeStubFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RecipeStubFilter {

public function __construct(
RecipeIdTypeFilter $recipeIdTypeFilter,
RecipeIdCopyFilter $recipeIdCopyFilter,
RecipeIdCopyFilter $recipeIdCopyFilter
) {
$this->filters = [
$recipeIdCopyFilter,
Expand Down
8 changes: 4 additions & 4 deletions lib/Helper/TimestampHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function parseTimestamp(string $timestamp): string {
// For now, we only support the ISO8601 format because it is required in the schema.org standard
try {
return $this->parseIsoFormat($timestamp);
} catch (InvalidTimestampException) {
} catch (InvalidTimestampException $ex) {
// We do nothing here. Check the next format
}

Expand All @@ -65,15 +65,15 @@ public function parseTimestamp(string $timestamp): string {
private function parseIsoFormat(string $timestamp): string {
try {
return $this->parseIsoCalendarDateFormat($timestamp, '-');
} catch (InvalidTimestampException) { // Check next format
} catch (InvalidTimestampException $ex) { // Check next format
}
try {
return $this->parseIsoCalendarDateFormat($timestamp, '');
} catch (InvalidTimestampException) { // Check next format
} catch (InvalidTimestampException $ex) { // Check next format
}
try {
return $this->parseIsoWeekDateFormat($timestamp, '-');
} catch (InvalidTimestampException) { // Check next format
} catch (InvalidTimestampException $ex) { // Check next format
}

return $this->parseIsoWeekDateFormat($timestamp, '');
Expand Down
Loading