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

Improve code quality, code documentation #4

Merged
merged 2 commits into from
Aug 27, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
push:
branches: [ 'master' ]
pull_request:
branches: [ 'master' ]

permissions:
contents: read

jobs:
run:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-versions: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]

name: Run Unit Test on PHP ${{ matrix.php-versions }}

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

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Check the PHP version
run: php -v

- name: Validate composer.json and composer.lock
run: composer validate --strict

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

- name: Run test suite
run: vendor/bin/phpunit --coverage-clover=coverage.clover

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.php-cs-fixer.cache
.phpunit.result.cache
app
build
composer.lock
docs
Expand Down
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to `Spark Plug` will be documented in this file.

## [0.7.0](https://github.com/rougin/spark-plug/compare/v0.6.1...v0.7.0) - Unreleased

### Added
- `Controller` for type-hinting `Codeigniter 3`'s libraries

### Changed
- Code documentation by `php-cs-fixer`, code quality by `phpstan`
- Workflow from `Travis CI` to `Github Actions`
- Code coverage from `Scrutinizer CI` to `Codecov`

## [0.6.1](https://github.com/rougin/spark-plug/compare/v0.6.0...v0.6.1) - 2018-12-11

### Added
Expand Down
106 changes: 53 additions & 53 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
{
"name": "rougin/spark-plug",
"description": "Codeigniter applications as single variables.",
"keywords": ["codeigniter", "instance", "php", "spark-plug"],
"homepage": "https://roug.in/spark-plug/",
"license": "MIT",
"authors":
[
{
"email": "[email protected]",
"homepage": "https://roug.in/",
"name": "Rougin Gutib",
"role": "Software Engineer"
}
],
"require":
"name": "rougin/spark-plug",
"description": "Codeigniter 3 in a single variable.",
"keywords": [ "codeigniter", "php", "spark-plug" ],
"homepage": "https://roug.in/spark-plug/",
"license": "MIT",
"authors":
[
{
"php": ">=5.4.0"
},
"require-dev":
{
"phpunit/phpunit": "~4.2|~5.7",
"rougin/codeigniter": "~3.0",
"scrutinizer/ocular": "~1.1.0"
},
"autoload":
{
"psr-4":
{
"Rougin\\SparkPlug\\": "src"
}
},
"autoload-dev":
{
"psr-4":
{
"Rougin\\SparkPlug\\": "tests"
}
},
"scripts":
"email": "[email protected]",
"homepage": "https://roug.in/",
"name": "Rougin Gutib",
"role": "Software Engineer"
}
],
"require":
{
"php": ">=5.4.0"
},
"require-dev":
{
"phpunit/phpunit": "~4.2|~5.7|~6.0|~7.0|~8.0|~9.0",
"rougin/codeigniter": "~3.0",
"sanmai/phpunit-legacy-adapter": "~6.1|~8.0"
},
"autoload":
{
"psr-4":
{
"test": "phpunit"
},
"extra":
"Rougin\\SparkPlug\\": "src"
}
},
"autoload-dev":
{
"psr-4":
{
"branch-alias":
{
"dev-master": "1.0-dev"
}
},
"suggest":
"Rougin\\SparkPlug\\": "tests"
}
},
"scripts":
{
"test": "phpunit"
},
"extra":
{
"branch-alias":
{
"rougin/codeigniter": "Packaged \"system\" folder of the Codeigniter framework.",
"rougin/combustor": "CRUD generator for the Codeigniter framework.",
"rougin/credo": "Doctrine ORM integration for the Codeigniter framework.",
"rougin/ignite": "Composer-based project for the Codeigniter framework.",
"rougin/refinery": "\"Ready-to-eat\" migrations for Codeigniter framework",
"rougin/wildfire": "Query Builder wrapper for the Codeigniter framework."
"dev-master": "1.0-dev"
}
},
"suggest":
{
"rougin/codeigniter": "Codeigniter 3's Composer-based package.",
"rougin/combustor": "A simple CRUD generator for Codeigniter 3.",
"rougin/credo": "A Doctrine ORM wrapper for Codeigniter 3.",
"rougin/ignite": "Codeigniter 3 as a Composer-based project.",
"rougin/refinery": "Database migrations for Codeigniter 3.",
"rougin/wildfire": "A Query Builder wrapper for Codeigniter 3."
}
}
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
level: 9
paths:
- src
- tests
excludePaths:
analyse:
- tests/Application/views
- tests/Codeigniter/application/views
scanDirectories:
- vendor/rougin/codeigniter/src
ignoreErrors:
- '#^Constant APPPATH not found\.$#'
- '#^Constant BASEPATH not found\.$#'
- '#^Constant ENVIRONMENT not found\.$#'
76 changes: 76 additions & 0 deletions phpstyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

// Specify the paths in this variable ---
$paths = array(__DIR__ . '/src');

$paths[] = __DIR__ . '/tests';
// --------------------------------------

// Specify the rules for code formatting ---------
$rules = array('@PSR12' => true);

$cscp = 'control_structure_continuation_position';
$rules[$cscp] = ['position' => 'next_line'];

$braces = array();
$braces['control_structures_opening_brace'] = 'next_line_unless_newline_at_signature_end';
$braces['functions_opening_brace'] = 'next_line_unless_newline_at_signature_end';
$braces['anonymous_functions_opening_brace'] = 'next_line_unless_newline_at_signature_end';
$braces['anonymous_classes_opening_brace'] = 'next_line_unless_newline_at_signature_end';
$braces['allow_single_line_empty_anonymous_classes'] = false;
$braces['allow_single_line_anonymous_functions'] = false;
$rules['braces_position'] = $braces;

$visibility = array('elements' => array());
$visibility['elements'] = array('method', 'property');
$rules['visibility_required'] = $visibility;

$rules['phpdoc_var_annotation_correct_order'] = true;

$rules['single_quote'] = ['strings_containing_single_quote_chars' => true];

$rules['no_unused_imports'] = true;

$rules['align_multiline_comment'] = true;

$rules['trim_array_spaces'] = true;

$order = ['case_sensitive' => true];
$order['null_adjustment'] = 'always_last';
$rules['phpdoc_types_order'] = $order;

$rules['new_with_parentheses'] = ['named_class' => false];

$rules['concat_space'] = ['spacing' => 'one'];

$rules['no_empty_phpdoc'] = true;

$groups = [];
$groups[] = ['template', 'extends'];
$groups[] = ['deprecated', 'link', 'see', 'since', 'codeCoverageIgnore'];
$groups[] = ['property', 'property-read', 'property-write'];
$groups[] = ['method'];
$groups[] = ['author', 'copyright', 'license'];
$groups[] = ['category', 'package', 'subpackage'];
$groups[] = ['param'];
$groups[] = ['return', 'throws'];
$rules['phpdoc_separation'] = ['groups' => $groups];

$align = ['align' => 'vertical'];
$align['tags'] = ['method', 'param', 'property', 'throws', 'type', 'var'];
$rules['phpdoc_align'] = $align;

$rules['statement_indentation'] = false;

$rules['align_multiline_comment'] = true;
// -----------------------------------------------

$finder = new \PhpCsFixer\Finder;

$finder->in((array) $paths);

$config = new \PhpCsFixer\Config;

$config->setRules($rules);

return $config->setFinder($finder);
40 changes: 40 additions & 0 deletions src/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rougin\SparkPlug;

/**
* @property \CI_Cache $cache
* @property \CI_Calendar $calendar
* @property \CI_Cart $cart
* @property \CI_Config $config
* @property \CI_DB $db
* @property \CI_Email $email
* @property \CI_Email $email
* @property \CI_Encrypt $encrypt
* @property \CI_Encryption $encryption
* @property \CI_Form_validation $form_validation
* @property \CI_FTP $ftp
* @property \CI_Image_lib $image_lib
* @property \CI_Javascript $javascript
* @property \CI_Jquery $jquery
* @property \CI_Migration $migration
* @property \CI_Pagination $pagination
* @property \CI_Parser $parser
* @property \CI_Profiler $profiler
* @property \CI_Table $table
* @property \CI_Trackback $trackback
* @property \CI_Typography $typography
* @property \CI_Unit_test $unit
* @property \CI_Upload $upload
* @property \CI_User_agent $agent
* @property \CI_Xmlrpc $xmlrpc
* @property \CI_Xmlrpcs $xmlrpcs
* @property \CI_Zip $zip
*
* @package SparkPlug
*
* @author Rougin Gutib <[email protected]>
*/
class Controller extends \CI_Controller
{
}
18 changes: 8 additions & 10 deletions src/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
namespace Rougin\SparkPlug;

/**
* Instance
*
* A static helper for the SparkPlug::instance method.
*
* @package SparkPlug
* @author Rougin Gutib <[email protected]>
*
* @author Rougin Gutib <[email protected]>
*/
class Instance
{
/**
* Creates an instance of CodeIgniter based on the application path.
* Creates a Codeigniter instance based on the application path.
*
* @param string $path
* @param array<string, string> $server
* @param array<string, string> $globals
*
* @param string $path
* @param array $server
* @param array $globals
* @return \CI_Controller
* @return \Rougin\SparkPlug\Controller
*/
public static function create($path = '', array $server = array(), array $globals = array())
{
Expand Down
Loading
Loading