Skip to content

Commit

Permalink
#132 pass level1
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Aug 28, 2024
1 parent a844895 commit a28f9ee
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 23 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ jobs:
- name: Check PHP syntax
run: composer lint

analyze:
name: Check PHP code quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHP Stan
run: composer analyze -- --error-format=github

assets:
name: Assets Test
runs-on: ubuntu-latest
Expand All @@ -94,7 +114,7 @@ jobs:

status-check:
name: Status Check
needs: [ test, assets, lint ]
needs: [ test, assets, lint, analyze ]
runs-on: ubuntu-latest
steps:
- name: Display Status
Expand Down
3 changes: 2 additions & 1 deletion app/Gianism/Api/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ abstract protected function get_result();
* @param array $argument
*/
protected function __construct( array $argument = array() ) {
parent::__construct( $argument );
add_action( 'wp_ajax_' . static::ACTION, array( $this, 'ajax' ) );
if ( ! static::ONLY_MEMBER ) {
add_action( 'wp_ajax_nopriv_' . static::ACTION, array( $this, 'ajax' ) );
Expand All @@ -64,7 +65,7 @@ protected function parse_result( array $result ) {
*/
public function ajax() {
try {
if ( static::NONCE_ACTION && ! wp_verify_nonce( $this->input->get( '_wpnonce' ), static::NONCE_ACTION ) ) {
if ( static::NONCE_ACTION && ! wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), static::NONCE_ACTION ) ) {
throw new \Exception( __( 'You have no permission.', 'wp-gianism' ), 403 );
}
$result = $this->get_result();
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Api/ShortCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ShortCodes extends Application {
* @param array $argument
*/
public function __construct( array $argument = [] ) {
parent::__construct( $argument );
add_shortcode( 'gianism_login', [ $this, 'login_short_code' ] );
add_shortcode( 'gianism_connection', [ $this, 'profile_connection_short_code' ] );
}
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static function init() {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// Register assets
add_action( 'init', array( $this, 'register_assets' ) );
// Admin page
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Admin extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
if ( $this->option->is_network_activated() && ! is_main_site() ) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion app/Gianism/Controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Login extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );

if ( $this->option->is_enabled() ) {
// Only for account holder
Expand Down Expand Up @@ -86,7 +87,7 @@ public function login_form( $before = '', $after = '', $register = false, $redir
$class_name[] = 'public-style';
break;
}
$class_name = empty( $class_name ) ? '' : sprintf( ' class="%s"', implode( ' ', $class_name ) );
$class_name = $class_name ? '' : sprintf( ' class="%s"', esc_attr( implode( ' ', $class_name ) ) );
$before = sprintf( '<div id="wpg-login"%s>', $class_name );
}
if ( empty( $after ) ) {
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Network extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// Add network notice
add_action( 'admin_notices', [ $this, 'network_notice' ] );
// Set role.
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Profile extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// If not enabled, skip.
if ( ! $this->option->is_enabled() ) {
return;
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/ProfileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ProfileChecker extends AbstractController {

public function __construct( array $argument = [] ) {
parent::__construct( $argument );
add_action( 'rest_api_init', [ $this, 'register_rest' ] );
add_action(
'init',
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Controller/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Rewrite extends AbstractController {
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
// Add query vars
add_filter( 'query_vars', [ $this, 'filter_vars' ] );
// Instance all instances
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Cron/Daily.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract class Daily extends AnalyticsFetcher {
* @param array $argument
*/
protected function __construct( array $argument = array() ) {
parent::__construct( $argument );
if ( ! wp_next_scheduled( $this->get_action() ) ) {
wp_schedule_event( $this->build_timestamp(), static::INTERVAL, $this->get_action() );
}
Expand Down
9 changes: 0 additions & 9 deletions app/Gianism/Helper/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
*/
class Input extends Singleton {

/**
* Constructor
*
* @param array $argument
*/
public function __construct( array $argument = array() ) {
// Do nothing because it's empty singleton
}

/**
* Short hand for $_GET
*
Expand Down
6 changes: 6 additions & 0 deletions app/Gianism/Helper/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

use Gianism\Pattern\Singleton;

/**
* Class for monitor social network
*
* @todo Implement this class
*/
class Monitor extends Singleton {


Expand All @@ -21,6 +26,7 @@ class Monitor extends Singleton {
* @param array $argument
*/
protected function __construct( array $argument = array() ) {
parent::__construct( $argument );
add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) );
}
}
6 changes: 2 additions & 4 deletions app/Gianism/Helper/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Option extends Singleton {
* @param array $argument Settings array.
*/
protected function __construct( array $argument = [] ) {
parent::__construct( $argument );
$this->values = $this->get( $this->key, [] );
foreach ( $this->default_option as $key => $value ) {
if ( ! isset( $this->values[ $key ] ) ) {
Expand Down Expand Up @@ -285,13 +286,10 @@ public function button_types() {
public function has_invalid_option( $name ) {
switch ( $name ) {
case 'google_redirect':
$option = $this->get( $this->key, [] );

$saved_option = $this->get( $this->key, [] );
return isset( $saved_option['ggl_redirect_uri'] ) && ! empty( $saved_option['ggl_redirect_uri'] );
break;
default:
return false;
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Helper/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ServiceManager extends Singleton {
*/
final protected function __construct( array $argument ) {
// Do nothing
parent::__construct( $argument );
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Helper/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function start() {
* @return bool
*/
public function is_available() {
// @phpstan-ignore isset.variable
return isset( $_COOKIE );
}

Expand Down
4 changes: 2 additions & 2 deletions app/Gianism/Pattern/Singleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ abstract class Singleton {
*
* @param array $argument
*/
protected function __construct( array $argument = [] ) {
// Do nothing.
protected function __construct( array $argument = [] ) { // @phpstan-ignore constructor.unusedParameter
// Override something.
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Plugins/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function __construct( array $argument = [] ) {
// Do nothing if Google is not enabled.
return;
}
parent::__construct( $argument );
// Add request handler
add_action( 'gianism_extra_action', [ $this, 'handle_default' ], 10, 3 );
// Register Ajax
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Plugins/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function __construct( array $argument = array() ) {
if ( ! $this->plugin_enabled() ) {
return;
}
parent::__construct( $argument );
// Post type
add_action( 'init', array( $this, 'register_post_type' ) );
add_action( "manage_{$this->post_type}_posts_custom_column", array( $this, 'custom_columns' ), 10, 2 );
Expand Down
1 change: 1 addition & 0 deletions app/Gianism/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class AbstractService extends Application {
* @param array $argument
*/
protected function __construct( array $argument = array() ) {
parent::__construct( $argument );
// Setup name
if ( empty( $this->verbose_service_name ) ) {
$this->verbose_service_name = $this->service_name;
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ parameters:

bootstrapFiles:
- vendor/autoload.php

editorUrlTitle: '%%relFile%%:%%line%%'
4 changes: 3 additions & 1 deletion templates/parts/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/** @var $this \Gianism\UI\Screen */

defined( 'ABSPATH' ) or die();

if ( ! isset( $this ) ) {
return;
}
?>

<div class="wrap gianism-wrap">
Expand Down
5 changes: 5 additions & 0 deletions templates/parts/sidebar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php
/** @var $this \Gianism\UI\Screen */

defined( 'ABSPATH' ) or die();
if ( ! isset( $this ) ) {
return;
}
?>
<div class="sidebar">
<div id="index">
Expand Down
7 changes: 5 additions & 2 deletions templates/setting/google.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
defined( 'ABSPATH' ) or die();
/** @var \Gianism\UI\Screen $this *
/** @var \Gianism\Service\Google $instance */
/** @var $this \Gianism\UI\Screen */
/** @var $instance \Gianism\Service\Google */
if ( ! isset( $this, $instance ) ) {
return;
}
?>

<h3><i class="lsf lsf-google"></i> Google</h3>
Expand Down
6 changes: 4 additions & 2 deletions templates/setup.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
/** @var $this \Gianism\UI\SettingScreen */

defined( 'ABSPATH' ) or die();

/** @var \Gianism\UI\SettingScreen $this */
if ( ! isset( $this ) ) {
return;
}

foreach ( $this->service->all_services() as $service ) {
/** @var \Gianism\Service\AbstractService $instance */
Expand Down

0 comments on commit a28f9ee

Please sign in to comment.