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
  • Loading branch information
iturgeon committed Jun 11, 2017
1 parent 6173b69 commit e4d8158
Show file tree
Hide file tree
Showing 38 changed files with 1,266 additions and 779 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'
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 testall",
"lint-docker": "docker-compose run --rm web php composer.phar lint",
"db-setup-docker": "docker-compose run --rm web php composer.phar dbsetup",
"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
151 changes: 126 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e4d8158

Please sign in to comment.