Skip to content

Commit

Permalink
Merge pull request #36 from sectsect/feature/add-phpstan
Browse files Browse the repository at this point in the history
add code linting with PHPStan
  • Loading branch information
sectsect authored Apr 28, 2024
2 parents fa035ce + 30a76ee commit d75bd56
Show file tree
Hide file tree
Showing 11 changed files with 1,652 additions and 33 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PHPStan

on:
push:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
phpstan:
runs-on: ubuntu-latest

name: Static Analysis

env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer:v2, cs2pr

- name: Composer install
run: composer install --optimize-autoloader --prefer-dist

- name: PHPStan
run: composer phpstan
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"swordev.phpstan"
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# <img src="https://github-sect.s3-ap-northeast-1.amazonaws.com/logo.svg" width="18" height="auto"> Google Spreadsheet to DB
[![PHP Unit Tests](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpunit.yml/badge.svg)](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpunit.yml) [![PHP Coding Standards](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpcs.yml/badge.svg)](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpcs.yml) [![Latest Stable Version](https://poser.pugx.org/sectsect/google-spreadsheet-to-db/v)](//packagist.org/packages/sectsect/google-spreadsheet-to-db)
[![PHP Unit Tests](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpunit.yml/badge.svg)](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpunit.yml) [![PHPStan](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpstan.yml/badge.svg)](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpstan.yml) [![PHP Coding Standards](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpcs.yml/badge.svg)](https://github.com/sectsect/google-spreadsheet-to-db/actions/workflows/phpcs.yml) [![Latest Stable Version](https://poser.pugx.org/sectsect/google-spreadsheet-to-db/v)](//packagist.org/packages/sectsect/google-spreadsheet-to-db)

### The "Google Spreadsheet to DB" plugin is designed for WordPress and facilitates the import of data from Google Sheets into a WordPress database using Google's [Sheets API](https://developers.google.com/sheets/api) (v4). It supports data manipulation before saving and is configurable via a WordPress admin interface.

Expand All @@ -9,7 +9,7 @@
- Admin Interface: Provides an admin page for easy management and configuration of the plugin settings.

## Requirements
- PHP version 7.4 or higher.
- PHP version 8.0 or higher.
- [Composer](https://getcomposer.org/) for managing PHP dependencies.

## Get Started
Expand Down
12 changes: 8 additions & 4 deletions admin/class-recursivetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,25 @@ public static function json_to_debug( string $json_text = '' ): string {
/**
* Recursively convert an array to an HTML table.
*
* @param array $arr Array to be converted.
* @param array<mixed> $arr Array to be converted.
* @return string HTML table representation of the array.
*/
private static function array_to_html_table_recursive( array $arr ): string {
$str = '<table><tbody>';
foreach ( $arr as $key => $val ) {
$str .= '<tr>';
$str .= "<th><span>$key</span></th>";
$str .= '<th><span>' . htmlspecialchars( $key ) . '</span></th>';
$str .= '<td>';
if ( is_array( $val ) ) {
if ( ! empty( $val ) ) {
$str .= self::array_to_html_table_recursive( $val );
}
} else {
$str .= "<span>$val</span>";
if ( ! is_string( $val ) ) {
return $str;
}
$value = $val;
$str .= '<span>' . htmlspecialchars( $value ) . '</span>';
}
$str .= '</td></tr>';
}
Expand Down Expand Up @@ -278,7 +282,7 @@ private static function array_to_html_table_recursive( array $arr ): string {
<?php endforeach; ?>
<?php
if ( function_exists( 'google_ss2db_options_pagination' ) ) {
google_ss2db_options_pagination( $paged, $max_num_pages, 2 );
google_ss2db_options_pagination( $paged, (int) $max_num_pages, 2 );
}
?>
</section>
Expand Down
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
],
"type": "wordpress-plugin",
"require": {
"php": ">=5.5"
"php": ">=5.5",
"google/apiclient": "^2.16"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^9.5",
"yoast/phpunit-polyfills": "^2.0",
"squizlabs/php_codesniffer": "^3.7",
"wp-coding-standards/wpcs": "^3.0"
"wp-coding-standards/wpcs": "^3.0",
"phpstan/phpstan": "^1.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.3"
},
"license": "GPL-3.0+",
"authors": [
Expand All @@ -28,7 +32,12 @@
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2048M",
"phpstan-clear": "vendor/bin/phpstan clear-result-cache"
}
}
Loading

0 comments on commit d75bd56

Please sign in to comment.