Skip to content

Commit

Permalink
adds phpcs for enforcing syntax rules and updates code to meet it
Browse files Browse the repository at this point in the history
adds php CodeSniffer to dev requirements
adds symfony 2 code standards to dev requirements
adds custom phpcs rules
applies all fixes required to pass errors for new phpcs rules
removes file system mocks not needed any longer
adds scripts for sniffing
  • Loading branch information
iturgeon committed Jun 11, 2017
1 parent 6173b69 commit 93c10f9
Show file tree
Hide file tree
Showing 40 changed files with 1,269 additions and 783 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ cache:
- $COMPOSER_CACHE_DIR
- vendor
install:
- 'composer install --no-scripts'
- 'composer install'
php:
- '5.4'
- '5.5'
- '5.6'
script:
- 'composer lint'
- 'composer sniff-summary'
- 'composer test'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Edit `config/localConfig.php`:
To create the required tables, run the creation script below. You'll need to complete the db steps above first.

```
$ php composer.phar dbsetup
$ php composer.phar db-setup
```

The table schema can be found in [bin/db_create_tables.php](bin/db_create_tables.php)
Expand Down Expand Up @@ -225,7 +225,7 @@ $ php composer.phar test
We included a Dockerfile, docker-compose.yml, and tests script to run your tests in a predictable environment. To run tests using docker run this command:

```
$ php composer.phar test:docker
$ php composer.phar test-docker
```

By default, we exclude functional tests that include external APIs. If you would like to run those tests, run this command:
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
}
],
"scripts": {
"postdeploy": "composer dbsetup"
"postdeploy": "composer db-setup"
}
}
18 changes: 7 additions & 11 deletions bin/db_create_tables.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
require_once(__DIR__.'/../config/settings.php');
global $db_type;
if ($db_type == 'sqlite' || $db_type == 'test')
{
if ('sqlite' === $db_type || 'test' === $db_type) {
// SQLITE (mostly for testing)
$tables = [
'
Expand Down Expand Up @@ -39,11 +38,10 @@
date_created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
date_completed timestamp with time zone
);
'
',
];
}
if ($db_type == 'pgsql')
{
if ('pgsql' === $db_type) {
// POSTGRESQL
$tables = [
'
Expand Down Expand Up @@ -80,11 +78,10 @@
date_created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
date_completed timestamp with time zone
);
'
',
];
}
if ($db_type == 'mysql')
{
if ('mysql' === $db_type) {
// MYSQL
$tables = [
'
Expand Down Expand Up @@ -125,12 +122,11 @@
`date_completed` timestamp,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
'
',
];
}

// run every query
foreach ($tables as $sql)
{
foreach ($tables as $sql) {
UdoitDB::query($sql);
}
53 changes: 27 additions & 26 deletions bin/move_reports_to_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,46 @@

$rows = $dbh->query("SELECT * FROM {$db_reports_table}")->fetchAll();

if( ! isset($rows[0]['file_path']))
{
exit("It looks like this script doesnt need to be run");
if (!isset($rows[0]['file_path'])) {
exit("It looks like this script doesnt need to be run");
}

if( ! isset($rows[0]['report_json']))
{
// Quick hack to add report column since we dont have migrations yet
$column_type = $db_type == 'mysql' ? 'MEDIUMTEXT' : 'TEXT';
$dbh->query("ALTER TABLE {$db_reports_table} ADD report_json {$column_type}");
if (!isset($rows[0]['report_json'])) {
// Quick hack to add report column since we dont have migrations yet
$column_type = $db_type === 'mysql' ? 'MEDIUMTEXT' : 'TEXT';
$dbh->query("ALTER TABLE {$db_reports_table} ADD report_json {$column_type}");
}

$sth = $dbh->prepare("UPDATE {$db_reports_table} set report_json = :report_json WHERE id = :id");
$count_moved = 0;

foreach ($rows as $row)
{
if(empty($row['file_path'])) continue;
foreach ($rows as $row) {
if (empty($row['file_path'])) {
continue;
}

$file = __DIR__. '/'. $row['file_path'];
if( ! file_exists($file)){
echo("Json file not found {$file} for report id: {$row['id']}\n");
continue;
}
$file = __DIR__."/{$row['file_path']}";
if (!file_exists($file)) {
echo("Json file not found {$file} for report id: {$row['id']}\n");
continue;
}

$json = file_get_contents($file);
$json = file_get_contents($file);

if(empty($json)) continue;
if (empty($json)) {
continue;
}

$sth->bindValue(':report_json', $json, PDO::PARAM_STR);
$sth->bindValue(':id', $row['id'], PDO::PARAM_INT);
$res = $sth->execute();
$sth->bindValue(':report_json', $json, PDO::PARAM_STR);
$sth->bindValue(':id', $row['id'], PDO::PARAM_INT);
$res = $sth->execute();

if(!$res){
echo("Failed inserting report for {$row['id']}");
continue;
}
if (!$res) {
echo("Failed inserting report for {$row['id']}");
continue;
}

$count_moved++;
++$count_moved;
}

$dbh->query("ALTER TABLE {$db_reports_table} DROP COLUMN file_path");
Expand Down
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
"license": "GPL-3.0",
"scripts":{
"test": "vendor/phpunit/phpunit/phpunit --exclude-group functional --coverage-html ./reports --coverage-text",
"testall": "vendor/phpunit/phpunit/phpunit",
"lint": "find . -type f -iname \"*.php\" -not -path \"./lib/quail/tests/*\" -not -path \"./vendor/*\" | xargs -n1 php -l",
"dbsetup" : "php bin/db_create_tables.php",
"test-all": "vendor/phpunit/phpunit/phpunit",
"lint": "./vendor/bin/parallel-lint --exclude vendor --exclude lib/quail .s",
"sniff": "./vendor/bin/phpcs --extensions=php .",
"sniff-errors-only": "./vendor/bin/phpcs -n --extensions=php .",
"sniff-summary": "./vendor/bin/phpcs --report=summary --extensions=php .",
"db-setup" : "php bin/db_create_tables.php",
"migrate" : "php bin/move_reports_to_db.php",
"start": "php -S localhost:8000 -t public/",

"test:docker": "docker-compose run --rm web php composer.phar test",
"testall:docker": "docker-compose run --rm web php composer.phar testall",
"lint:docker": "docker-compose run --rm web php composer.phar lint",
"dbsetup:docker": "docker-compose run --rm web php composer.phar dbsetup",
"start:docker": "docker-compose run --rm web php -S localhost:8000 -t public/"
"test-docker": "docker-compose run --rm web php composer.phar test",
"test-all-docker": "docker-compose run --rm web php composer.phar test-all",
"lint-docker": "docker-compose run --rm web php composer.phar lint",
"db-setup-docker": "docker-compose run --rm web php composer.phar db-setup",
"start-docker": "docker-compose run --rm web php -S localhost:8000 -t public/"
},
"repositories" : [
{
Expand Down Expand Up @@ -55,7 +58,9 @@
"symfony/yaml": "v2.8.9",
"heroku/heroku-buildpack-php": "v121",
"mockery/mockery": "^0.9.9",
"mikey179/vfsStream": "^1.6"
"jakub-onderka/php-parallel-lint": "^0.9.2",
"squizlabs/php_codesniffer": "^3.0",
"escapestudios/symfony2-coding-standard": "3.x-dev"
},
"autoload": {
"psr-0": {
Expand Down
Loading

0 comments on commit 93c10f9

Please sign in to comment.