Skip to content
Merged
49 changes: 46 additions & 3 deletions .github/workflows/php-sast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,56 @@ jobs:
# - name: Validate composer.json and composer.lock
# run: composer validate --strict

# This config file gets auto-loaded by PHPStan
# !!!! The old bcc-signon plugin and the bcc-wp-proxy plugin are excluded from analysis!
- name: Set PHPStan config
run: |
cat <<'EOF' > phpstan.neon
parameters:
level: 1 # form 0 to 11 where 0 is the loosest and 11 the strictest
errorFormat: github
paths:
- plugins
scanFiles:
- custom-defs.stub
bootstrapFiles:
- plugins/bcc-login/bcc-login.php
ignoreErrors:
- '#Path in require\(\) "build/.+\.asset\.php" is not a file or it does not exist\.#'
excludePaths:
- plugins/bcc-signon/*
- plugins/bcc-wp-proxy/*
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
EOF

- name: Create custom stubs for plugin functions. If this grows too big it can be commited as a separate file
run: |
cat <<'EOF' > custom-defs.stub
<?php

/**
* @param mixed $post_id
* @return mixed|null
*/
function get_field(
string $selector,
$post_id = false,
bool $format_value = true,
bool $escape_html = false
) {};

/**
* @return string
*/
function get_culture() {};
EOF

- name: Install PHPStan and Wordpress-stub
run: |
composer require --dev phpstan/phpstan
composer require --dev szepeviktor/phpstan-wordpress
composer config --no-plugins allow-plugins.phpstan/extension-installer true
composer require --dev phpstan/extension-installer

- name: Run PHPStan
run: vendor/bin/phpstan analyse plugins/* --error-format github --no-progress
run: vendor/bin/phpstan analyse --no-progress

Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function update( $transient ) {

}

public function purge(){
public function purge( $upgrader_object, $options ){

if (
$this->cache_allowed
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/bcc-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function __construct(){
$this->_users = new BCC_Login_Users($this->_settings);
$this->_visibility = new BCC_Login_Visibility( $this->_settings, $this->_client, $this->_coreapi );
$this->_widgets = new BCC_Login_Widgets( $this->_settings, $this->_client );
$this->_feed = new BCC_Login_Feed( $this->_settings, $this->_client, $this->_visibility );
$this->_feed = new BCC_Login_Feed( $this->_settings, $this->_client );
$this->_updater = new BCC_Login_Updater( $this->plugin, $this->plugin_slug, $this->plugin_version, $this->plugin_name );
$this->_notifications = new BCC_Notifications( $this->_settings, $this->_coreapi );

Expand Down
5 changes: 3 additions & 2 deletions plugins/bcc-login/endpoints/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
/** backchannel logout */
$logout_token = $_POST['logout_token'];
$token_id = '';
$state = '';

if ( $logout_token )
{
// OIDC backchannel logout. Retrieve session ID from logout_token.
$logout_token_claims = BCC_Login_Token_Utility::get_token_claims( $logout_token );
$sid = $logout_token_claims['sid'];
if ( $sid && ! empty ( $sid )) {
$sid = $logout_token_claims['sid'] ?? '';
if ( ! empty ( $sid ) ) {
$token_id = md5 ( $sid );
}
if ( ! empty( $token_id ) ) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/bcc-login/includes/class-bcc-login-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ function create_new_user( $person_id, $email, $id_token_claims ) {
'user_email' => $email,
'display_name' => $displayname,
'nickname' => $nickname,
'first_name' => isset( $user_claim['given_name'] ) ? $user_claim['given_name'] : '',
'last_name' => isset( $user_claim['family_name'] ) ? $user_claim['family_name'] : '',
'first_name' => isset( $id_token_claims['given_name'] ) ? $id_token_claims['given_name'] : '',
'last_name' => isset( $id_token_claims['family_name'] ) ? $id_token_claims['family_name'] : '',
);

// Create the new user.
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/includes/class-bcc-login-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function __construct( BCC_Login_Settings $settings ) {

add_action( 'init', array( $this, 'add_rewrite_rules' ) );
add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
add_action( 'template_include', array( $this, 'include_endpoint' ), 99 );
add_filter( 'template_include', array( $this, 'include_endpoint' ), 99 );
}

/**
Expand Down
3 changes: 1 addition & 2 deletions plugins/bcc-login/includes/class-bcc-login-feed.php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BCC_Login_Visibility $visibility not used anywhere so removing it

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
class BCC_Login_Feed {
private BCC_Login_Settings $_settings;
private BCC_Login_Client $_client;
private BCC_Login_Visibility $_visibility;

function __construct( BCC_Login_Settings $settings, BCC_Login_Client $client, BCC_Login_Visibility $visibility ) {
function __construct( BCC_Login_Settings $settings, BCC_Login_Client $client ) {
$this->_settings = $settings;
$this->_client = $client;
add_action( 'pre_get_posts', array( $this, 'add_paging_support') );
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/includes/class-bcc-login-settings.php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getenv returns false or env var value

Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function __construct () {
$settings->$key = constant( $constant );
} else {
$env = getenv( $constant );
if ( isset( $env ) && ! is_null( $env ) && $env != '') {
if ( $env !== false && $env != '') {
$settings->$key = $env;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/includes/class-bcc-login-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function update( $transient ) {

}

public function purge(){
public function purge( $upgrader_object, $options ){

if (
$this->cache_allowed
Expand Down
4 changes: 2 additions & 2 deletions plugins/bcc-login/includes/class-bcc-login-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ function on_block_editor_assets() {
* applies to category lists and REST API results.
*
* @param WP_Query $query
* @return WP_Query
* @return void
*/
function filter_pre_get_posts( $query ) {
// Don't filter posts for Phrase
Expand Down Expand Up @@ -1158,7 +1158,7 @@ function render_visibility_meta_box_to_attachments( $post ) {
/**
* Save visibility value to attachments.
*/
function save_visibility_to_attachments( $attach_id ) {
function save_visibility_to_attachments( $attach_id, $post_after, $post_before ) {
if ( !current_user_can( 'edit_post', $attach_id ) ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/includes/class-bcc-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function send_notification($post_id) {

$templates = array_key_exists($wp_lang, $this->settings->notification_templates)
? $this->settings->notification_templates[$wp_lang]
: (array_key_exists($site_language, $this->_settings->notification_templates)
: (array_key_exists($site_language, $this->settings->notification_templates)
? $this->settings->notification_templates[$site_language]
: null);

Expand Down
2 changes: 0 additions & 2 deletions plugins/bcc-login/includes/class-bcc-storage.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

class BCC_Storage {
private BCC_Encryption $_encryption;

private $_encryption_key;
private $_encryption_method = "AES-256-CBC";

Expand Down
6 changes: 3 additions & 3 deletions plugins/bcc-login/snippets/login-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
(function () {
var webAuth = new auth0.WebAuth({
domain: 'login.bcc.no',
clientID: '<?= $clientID ?>',
scope: '<?= $scope ?>',
clientID: '<?= $clientID ?? '' ?>',
scope: '<?= $scope ?? '' ?>',
responseType: 'id_token',
responseMode: 'fragment',
redirectUri: location.origin + '/<?= $redirectPath ?>'
redirectUri: location.origin + '/<?= $redirectPath ?? '' ?>'
});
setTimeout(function () {
webAuth.checkSession({prompt: 'none'}, function (err, authResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function update( $transient ) {

}

public function purge(){
public function purge( $upgrader_object, $options ){

if (
$this->cache_allowed
Expand Down