Skip to content

Commit

Permalink
Switch to official coding standard (#5038)
Browse files Browse the repository at this point in the history
* Switch to official coding standard

* Update .no-header.php-cs-fixer.dist.php

Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
  • Loading branch information
paulbalandan and samsonasik authored Sep 2, 2021
1 parent cca4660 commit 4ab9d66
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 719 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Install dependencies
run: |
composer update --ansi --no-interaction
composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config
composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config codeigniter/coding-standard
php -r 'file_put_contents("vendor/laminas/laminas-zendframework-bridge/src/autoload.php", "");'
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
Expand Down
16 changes: 8 additions & 8 deletions .no-header.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
* the LICENSE file that was distributed with this source code.
*/

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use Nexus\CsConfig\Fixer\Comment\SpaceAfterCommentStartFixer;
use Nexus\CsConfig\FixerGenerator;
use PhpCsFixer\Finder;
use Utils\PhpCsFixer\CodeIgniter4;
use Utils\PhpCsFixer\Fixer\Comment\SpaceAfterCommentStartFixer;

$finder = Finder::create()
->files()
->in([
__DIR__ . '/admin',
__DIR__ . '/app',
__DIR__ . '/public',
]);
])
->notName('#Logger\.php$#');

$overrides = [];

$options = [
'cacheFile' => 'build/.no-header.php-cs-fixer.cache',
'finder' => $finder,
'customFixers' => [
new SpaceAfterCommentStartFixer(),
],
'customRules' => [
'CodeIgniter4/space_after_comment_start' => true,
'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'),
'customRules' => [
SpaceAfterCommentStartFixer::name() => true,
],
];

Expand Down
13 changes: 6 additions & 7 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
* the LICENSE file that was distributed with this source code.
*/

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use Nexus\CsConfig\Fixer\Comment\SpaceAfterCommentStartFixer;
use Nexus\CsConfig\FixerGenerator;
use PhpCsFixer\Finder;
use Utils\PhpCsFixer\CodeIgniter4;
use Utils\PhpCsFixer\Fixer\Comment\SpaceAfterCommentStartFixer;

$finder = Finder::create()
->files()
Expand All @@ -37,11 +38,9 @@
$options = [
'cacheFile' => 'build/.php-cs-fixer.cache',
'finder' => $finder,
'customFixers' => [
new SpaceAfterCommentStartFixer(),
],
'customRules' => [
'CodeIgniter4/space_after_comment_start' => true,
'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'),
'customRules' => [
SpaceAfterCommentStartFixer::name() => true,
],
];

Expand Down
5 changes: 3 additions & 2 deletions admin/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"psr/log": "^1.1"
},
"require-dev": {
"codeigniter/coding-standard": "^1.1",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.1",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.1",
"nexusphp/cs-config": "^3.3",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1"
},
Expand Down
19 changes: 10 additions & 9 deletions app/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
*/
class Services extends BaseService
{
// public static function example($getShared = true)
// {
// if ($getShared)
// {
// return static::getSharedInstance('example');
// }
//
// return new \CodeIgniter\Example();
// }
/*
* public static function example($getShared = true)
* {
* if ($getShared) {
* return static::getSharedInstance('example');
* }
*
* return new \CodeIgniter\Example();
* }
*/
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"psr/log": "^1.1"
},
"require-dev": {
"codeigniter/coding-standard": "^1.1",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.1",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.1",
"nexusphp/cs-config": "^3.3",
"nexusphp/tachycardia": "^1.0",
"phpstan/phpstan": "^0.12.91",
"phpunit/phpunit": "^9.1",
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
// we have nothing more to do other than escape the item
//
// NOTE: The ! empty() condition prevents this method
// from breaking when QB isn't enabled.
// from breaking when QB isn't enabled.
if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables, true)) {
if ($protectIdentifiers === true) {
foreach ($parts as $key => $val) {
Expand Down
4 changes: 2 additions & 2 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,8 @@ protected function prepQEncoding($str)

if ($this->charset === 'UTF-8') {
// Note: We used to have mb_encode_mimeheader() as the first choice
// here, but it turned out to be buggy and unreliable. DO NOT
// re-add it! -- Narf
// here, but it turned out to be buggy and unreliable. DO NOT
// re-add it! -- Narf
if (extension_loaded('iconv')) {
$output = @iconv_mime_encode('', $str, [
'scheme' => 'Q',
Expand Down
2 changes: 1 addition & 1 deletion system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public function __set(string $key, $value)
public function __get(string $key)
{
// Note: Keep this order the same, just in case somebody wants to
// use 'session_id' as a session data key, for whatever reason
// use 'session_id' as a session data key, for whatever reason
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}
Expand Down
5 changes: 0 additions & 5 deletions system/Test/Mock/MockIncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

class MockIncomingRequest extends IncomingRequest
{
// public function populateHeaders()
// {
// // Don't do anything... force the tester to manually set the headers they want.
// }

protected function detectURI($protocol, $baseURL)
{
// Do nothing...
Expand Down
4 changes: 2 additions & 2 deletions system/Typography/Typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
continue;
}

// Force a newline to make sure end tags get processed by _format_newlines()
// Force a newline to make sure end tags get processed by _format_newlines()
if ($i === $c) {
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br /> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand Down
17 changes: 9 additions & 8 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ public function testWait()
// The problem: if the block below is enabled, the phpunit tests
// go catatonic when it is executed, presumably because of
// the CLI::input() waiting for a key press
// // test the press any key to continue...
// stream_filter_register('CLITestKeyboardFilter', 'CodeIgniter\CLI\CLITestKeyboardFilter');
// $spoofer = stream_filter_append(STDIN, 'CLITestKeyboardFilter');
// $time = time();
// CLITestKeyboardFilter::$spoofed = ' ';
// CLI::wait(0);
// stream_filter_remove($spoofer);
// $this->assertEquals(0, time() - $time);
//
// // test the press any key to continue...
// stream_filter_register('CLITestKeyboardFilter', 'CodeIgniter\CLI\CLITestKeyboardFilter');
// $spoofer = stream_filter_append(STDIN, 'CLITestKeyboardFilter');
// $time = time();
// CLITestKeyboardFilter::$spoofed = ' ';
// CLI::wait(0);
// stream_filter_remove($spoofer);
// $this->assertEquals(0, time() - $time);
}

public function testIsWindows()
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Cache/Handlers/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public function testDecrement()
$this->fileHandler->save(self::$key1, 10);
$this->fileHandler->save(self::$key2, 'value');

// Line following commented out to force the cache to add a zero entry for key3
// $this->fileHandler->save(self::$key3, 0);
// Line following commented out to force the cache to add a zero entry for key3
// $this->fileHandler->save(self::$key3, 0);

$this->assertSame(9, $this->fileHandler->decrement(self::$key1, 1));
$this->assertFalse($this->fileHandler->decrement(self::$key2, 1));
Expand Down
11 changes: 0 additions & 11 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ public function testNewImage()
$this->assertInstanceOf(ImageHandlerInterface::class, $actual);
}

// public function testNewMigrationRunner()
// {
// //FIXME - docs aren't clear about setting this up to just make sure that the service
// // returns a MigrationRunner
// $config = new \Config\Migrations();
// $db = new \CodeIgniter\Database\MockConnection([]);
// $this->expectException('InvalidArgumentException');
// $actual = Services::migrations($config, $db);
// $this->assertInstanceOf(\CodeIgniter\Database\MigrationRunner::class, $actual);
// }
//
public function testNewNegotiatorWithNullConfig()
{
$actual = Services::negotiator(null);
Expand Down
13 changes: 0 additions & 13 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,19 +643,6 @@ public function testToFormattedDateString()
$this->assertSame('May 10, 2017', $time->toFormattedDateString());
}

/**
* Unfortunately, ubuntu 14.04 (on TravisCI) fails this test and
* shows a numeric version of the month instead of the textual version.
* Confirmed on CentOS 7 as well.
* Example: format 'MMM' for November returns 'M02' instead of 'Nov'
* Not sure what the fix is just yet....
*/
// public function testToFormattedDateString()
// {
// $time = Time::parse('February 10, 2017', 'America/Chicago');
// $this->assertEquals('Feb 10, 2017', $time->toFormattedDateString());
// }

public function testToTimeString()
{
$time = Time::parse('January 10, 2017 13:20:33', 'America/Chicago');
Expand Down
10 changes: 0 additions & 10 deletions tests/system/Test/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
*/
final class TestCaseTest extends CIUnitTestCase
{
// protected function tearDown(): void
// {
// $buffer = ob_clean();
// if (ob_get_level() > 0)
// {
// ob_end_clean();
// }
// }
//
public function testGetPrivatePropertyWithObject()
{
$obj = new __TestForReflectionHelper();
Expand Down Expand Up @@ -86,7 +77,6 @@ public function testPHPUnitHeadersEmitted()
$response->send();
ob_end_clean();

// Did PHPunit do its thing?
$this->assertHeaderEmitted('Content-type: text/html;');
$this->assertHeaderNotEmitted('Set-Cookie: foo=bar;');
}
Expand Down
Loading

0 comments on commit 4ab9d66

Please sign in to comment.