Skip to content

Commit

Permalink
Merge pull request #48 from datamweb/add-github-action
Browse files Browse the repository at this point in the history
chore: add github action for Rector/PHPStan
  • Loading branch information
datamweb authored Aug 27, 2023
2 parents 4c687d7 + 99153ef commit 42c4150
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 40 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: PHPStan

on:
pull_request:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'phpstan*'
- '.github/workflows/phpstan.yml'
push:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'phpstan*'
- '.github/workflows/phpstan.yml'

jobs:
build:
name: PHP ${{ matrix.php-versions }} Static Analysis
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1']

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpstan, phpunit
extensions: intl, json, mbstring, xml
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Create PHPStan cache directory
run: mkdir -p build/phpstan

- name: Cache PHPStan results
uses: actions/cache@v3
with:
path: build/phpstan
key: ${{ runner.os }}-phpstan-${{ github.sha }}
restore-keys: ${{ runner.os }}-phpstan-

- name: Install dependencies
run: |
if [ -f composer.lock ]; then
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
else
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
fi
- name: Run static analysis
run: vendor/bin/phpstan analyze
66 changes: 66 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Rector

on:
pull_request:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'rector.php'
- '.github/workflows/rector.yml'
push:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'rector.php'
- '.github/workflows/rector.yml'

jobs:
build:
name: PHP ${{ matrix.php-versions }} Rector Analysis
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1']

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

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpstan
extensions: intl, json, mbstring, xml
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: |
if [ -f composer.lock ]; then
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
else
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
fi
- name: Analyze for refactoring
run: |
composer global require --dev rector/rector:^0.15.1
rector process --dry-run --no-progress-bar
60 changes: 30 additions & 30 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$client has no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$config has no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
];
// $ignoreErrors[] = [
// 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$client has no type specified\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
// ];
// $ignoreErrors[] = [
// 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GithubOAuth\\:\\:\\$config has no type specified\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
// ];
// $ignoreErrors[] = [
// 'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GithubOAuth.php',
// ];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
Expand All @@ -119,20 +119,20 @@
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$client has no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$config has no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
];
// $ignoreErrors[] = [
// 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$client has no type specified\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
// ];
// $ignoreErrors[] = [
// 'message' => '#^Property Datamweb\\\\ShieldOAuth\\\\Libraries\\\\GoogleOAuth\\:\\:\\$config has no type specified\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
// ];
// $ignoreErrors[] = [
// 'message' => '#^Variable \\$usersColumnsName might not be defined\\.$#',
// 'count' => 1,
// 'path' => __DIR__ . '/src/Libraries/GoogleOAuth.php',
// ];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
11 changes: 6 additions & 5 deletions src/Libraries/GithubOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Datamweb\ShieldOAuth\Libraries;

use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
use Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth;
use Exception;
Expand All @@ -24,8 +25,8 @@ class GithubOAuth extends AbstractOAuth
public static string $API_USER_INFO_URL = 'https://api.github.com/user';
private static string $APPLICATION_NAME = 'ShieldOAuth';
protected string $token;
protected $client;
protected $config;
protected CURLRequest $client;
protected ?object $config = null;
protected string $client_id;
protected string $client_secret;
protected string $callback_url;
Expand Down Expand Up @@ -93,15 +94,15 @@ protected function fetchUserInfoWithToken(): object
protected function setColumnsName(string $nameOfProcess, $userInfo): array
{
if ($nameOfProcess === 'syncingUserInfo') {
$usersColumnsName = [
return [
$this->config->usersColumnsName['first_name'] => $userInfo->name,
$this->config->usersColumnsName['last_name'] => $userInfo->name,
$this->config->usersColumnsName['avatar'] => $userInfo->avatar_url,
];
}

if ($nameOfProcess === 'newUser') {
$usersColumnsName = [
return [
'username' => $userInfo->login,
'email' => $userInfo->email,
'password' => random_string('crypto', 32),
Expand All @@ -112,6 +113,6 @@ protected function setColumnsName(string $nameOfProcess, $userInfo): array
];
}

return $usersColumnsName;
return [];
}
}
11 changes: 6 additions & 5 deletions src/Libraries/GoogleOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Datamweb\ShieldOAuth\Libraries;

use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
use Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth;
use Exception;
Expand All @@ -24,8 +25,8 @@ class GoogleOAuth extends AbstractOAuth
private static string $API_USER_INFO_URL = 'https://www.googleapis.com/oauth2/v3/userinfo';
private static string $APPLICATION_NAME = 'ShieldOAuth';
protected string $token;
protected $client;
protected $config;
protected CURLRequest $client;
protected ?object $config = null;
protected string $client_id;
protected string $client_secret;
protected string $callback_url;
Expand Down Expand Up @@ -93,15 +94,15 @@ protected function fetchUserInfoWithToken(): object
protected function setColumnsName(string $nameOfProcess, $userInfo): array
{
if ($nameOfProcess === 'syncingUserInfo') {
$usersColumnsName = [
return [
$this->config->usersColumnsName['first_name'] => $userInfo->name,
$this->config->usersColumnsName['last_name'] => $userInfo->family_name,
$this->config->usersColumnsName['avatar'] => $userInfo->picture,
];
}

if ($nameOfProcess === 'newUser') {
$usersColumnsName = [
return [
// users tbl // OAuth
'username' => $userInfo->given_name,
'email' => $userInfo->email,
Expand All @@ -113,6 +114,6 @@ protected function setColumnsName(string $nameOfProcess, $userInfo): array
];
}

return $usersColumnsName;
return [];
}
}

0 comments on commit 42c4150

Please sign in to comment.