Skip to content

Commit

Permalink
Add basic linting & CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jul 22, 2019
1 parent 99f2d27 commit 476c3fd
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 92 deletions.
48 changes: 48 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 2.1

orbs:
default:
executors:
node-10:
docker:
- image: 'circleci/node:10-stretch'
php-73:
docker:
- image: 'circleci/php:7.3-stretch'
jobs:
build-php:
executor: php-73
steps:
- run: php -v
- checkout
- restore_cache:
keys:
- composer-v1-{{ checksum "composer.lock" }}
- composer-v1-
- run: composer install -n --prefer-dist --no-scripts --no-suggest
- run: composer lint
- save_cache:
key: composer-v1-{{ checksum "composer.lock" }}
paths:
- vendor
build-node:
executor: node-10
steps:
- run: yarn versions
- checkout
- restore_cache:
keys:
- node-v1-{{ checksum "yarn.lock" }}
- node-v1-
- run: yarn install --frozen-lockfile
- run: yarn run docs:build
- save_cache:
key: node-v1-{{ checksum "yarn.lock" }}
paths:
- node_modules

workflows:
build:
jobs:
- default/build-node
- default/build-php
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
]
},
"require": {
"php": ">=7.1"
"php": ">=7.1.3"
},
"scripts": {
"lint": [
"phpcs --ignore=vendor,tests --extensions=php --standard=PSR12 ."
]
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4"
}
}
58 changes: 55 additions & 3 deletions composer.lock

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

11 changes: 3 additions & 8 deletions src/Directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

namespace Log1x\SageDirectives;

/**
* Return if Directives already exists.
*/
if (class_exists('Directives')) {
return;
}

/**
* Directives
*/
Expand Down Expand Up @@ -50,7 +43,7 @@ public function __construct()
*/
protected function get($name)
{
if (file_exists($directives = __DIR__.'/Directives/'.$name.'.php')) {
if (file_exists($directives = __DIR__ . '/Directives/' . $name . '.php')) {
return require_once($directives);
}
}
Expand Down Expand Up @@ -89,6 +82,8 @@ protected function blade()
}
}

// phpcs:disable
if (function_exists('add_action')) {
new Directives();
}
// phpcs:enable
26 changes: 13 additions & 13 deletions src/Directives/ACF.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
if (str_contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>".
return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>" .
"<?php while (have_rows({$expression->get(0)}, {$expression->get(1)})) : the_row(); ?>";
}

return "<?php if (have_rows({$expression})) : ?>".
return "<?php if (have_rows({$expression})) : ?>" .
"<?php while (have_rows({$expression})) : the_row(); ?>";
},

Expand Down Expand Up @@ -82,15 +82,15 @@
$expression = Util::parse($expression);

if (! empty($expression->get(3)) && ! is_string($expression->get(2))) {
return "<?php if (get_field({$expression->get(0)}, {$expression->get(3)})[{$expression->get(1)}] === {$expression->get(2)}) : ?>";
return "<?php if (get_field({$expression->get(0)}, {$expression->get(3)})[{$expression->get(1)}] === {$expression->get(2)}) : ?>"; // phpcs:ignore
}

if (! empty($expression->get(2)) && ! is_string($expression->get(2))) {
return "<?php if (get_field({$expression->get(0)}, {$expression->get(2)}) === {$expression->get(1)}) : ?>";
return "<?php if (get_field({$expression->get(0)}, {$expression->get(2)}) === {$expression->get(1)}) : ?>"; // phpcs:ignore
}

if (! empty($expression->get(2)) && is_string($expression->get(2))) {
return "<?php if (get_field({$expression->get(0)})[{$expression->get(2)}] === {$expression->get(1)}) : ?>";
return "<?php if (get_field({$expression->get(0)})[{$expression->get(2)}] === {$expression->get(1)}) : ?>"; // phpcs:ignore
}

return "<?php if (get_field({$expression->get(0)}) === {$expression->get(1)}) : ?>";
Expand Down Expand Up @@ -126,7 +126,7 @@
$expression = Util::parse($expression);

if (! empty($expression->get(2))) {
return "<?php if (get_sub_field({$expression->get(0)})[{$expression->get(1)}][{$expression->get(2)}]) : ?>";
return "<?php if (get_sub_field({$expression->get(0)})[{$expression->get(1)}][{$expression->get(2)}]) : ?>"; // phpcs:ignore
}

return "<?php if (get_sub_field({$expression->get(0)})[{$expression->get(1)}]) : ?>";
Expand All @@ -140,7 +140,7 @@
$expression = Util::parse($expression);

if (! empty($expression->get(2))) {
return "<?php if (get_sub_field({$expression->get(0)})[{$expression->get(1)}] === {$expression->get(2)}) : ?>";
return "<?php if (get_sub_field({$expression->get(0)})[{$expression->get(1)}] === {$expression->get(2)}) : ?>"; // phpcs:ignore
}

return "<?php if (get_sub_field({$expression->get(0)}) === {$expression->get(1)}) : ?>";
Expand All @@ -161,11 +161,11 @@
if (str_contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>".
return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>" .
"<?php while (have_rows({$expression->get(0)}, {$expression->get(1)})) : the_row(); ?>";
}

return "<?php if (have_rows({$expression})) : ?>".
return "<?php if (have_rows({$expression})) : ?>" .
"<?php while (have_rows({$expression})) : the_row(); ?>";
},

Expand Down Expand Up @@ -197,11 +197,11 @@
if (str_contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>".
return "<?php if (have_rows({$expression->get(0)}, {$expression->get(1)})) : ?>" .
"<?php while (have_rows({$expression->get(0)}, {$expression->get(1)})) : the_row(); ?>";
}

return "<?php if (have_rows({$expression})) : ?>".
return "<?php if (have_rows({$expression})) : ?>" .
"<?php while (have_rows({$expression})) : the_row(); ?>";
},

Expand All @@ -216,7 +216,7 @@
*/

'options' => function ($expression) {
return "<?php if (have_rows({$expression}, 'option')) : ?>".
return "<?php if (have_rows({$expression}, 'option')) : ?>" .
"<?php while (have_rows({$expression}, 'option')) : the_row(); ?>";
},

Expand Down Expand Up @@ -255,7 +255,7 @@
$expression = Util::parse($expression);

if (! empty($expression->get(2))) {
return "<?php if (get_field({$expression->get(0)}, 'option')[{$expression->get(1)}] === {$expression->get(2)}) : ?>";
return "<?php if (get_field({$expression->get(0)}, 'option')[{$expression->get(1)}] === {$expression->get(2)}) : ?>"; // phpcs:ignore
}

return "<?php if (get_field({$expression->get(0)}, 'option') === {$expression->get(1)}) : ?>";
Expand Down
34 changes: 17 additions & 17 deletions src/Directives/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
if (str_contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (isset({$expression->get(0)}) && (bool) {$expression->get(0)} === true) : ?>".
"<?php echo {$expression->get(1)}; ?>".
return "<?php if (isset({$expression->get(0)}) && (bool) {$expression->get(0)} === true) : ?>" .
"<?php echo {$expression->get(1)}; ?>" .
"<?php endif; ?>";
}

Expand All @@ -39,8 +39,8 @@
if (str_contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (isset({$expression->get(0)}) && (bool) {$expression->get(0)} === false) : ?>".
"<?php echo {$expression->get(1)}; ?>".
return "<?php if (isset({$expression->get(0)}) && (bool) {$expression->get(0)} === false) : ?>" .
"<?php echo {$expression->get(1)}; ?>" .
"<?php endif; ?>";
}

Expand Down Expand Up @@ -178,7 +178,7 @@
*/

'repeat' => function ($expression) {
return "<?php for (\$iteration = 0 ; \$iteration < (int) {$expression}; \$iteration++) : ?>".
return "<?php for (\$iteration = 0 ; \$iteration < (int) {$expression}; \$iteration++) : ?>" .
"<?php \$loop = (object) [
'index' => \$iteration,
'iteration' => \$iteration + 1,
Expand All @@ -201,7 +201,7 @@

'style' => function ($expression) {
if (! empty($expression)) {
return '<link rel="stylesheet" href="'.Util::strip($expression).'">';
return '<link rel="stylesheet" href="' . Util::strip($expression) . '">';
}

return '<style>';
Expand All @@ -219,7 +219,7 @@

'script' => function ($expression) {
if (! empty($expression)) {
return '<script src="'.Util::strip($expression).'"></script>';
return '<script src="' . Util::strip($expression) . '"></script>';
}

return '<script>';
Expand All @@ -239,8 +239,8 @@
$expression = Util::parse($expression);
$variable = Util::strip($expression->get(0));

return "<script>\n".
"window.{$variable} = <?php echo is_array({$expression->get(1)}) ? json_encode({$expression->get(1)}) : '\''.{$expression->get(1)}.'\''; ?>;\n".
return "<script>\n" .
"window.{$variable} = <?php echo is_array({$expression->get(1)}) ? json_encode({$expression->get(1)}) : '\'' . {$expression->get(1)} . '\''; ?>;\n" . // phpcs:ignore
"</script>";
},

Expand All @@ -251,19 +251,19 @@
*/

'inline' => function ($expression) {
$output = "/* {$expression} */\n".
$output = "/* {$expression} */\n" .
"<?php include get_theme_file_path({$expression}) ?>\n";

if (ends_with($expression, ".html'")) {
return $output;
}

if (ends_with($expression, ".css'")) {
return "<style>\n". $output .'</style>';
return "<style>\n" . $output . '</style>';
}

if (ends_with($expression, ".js'")) {
return "<script>\n". $output .'</script>';
return "<script>\n" . $output . '</script>';
}
},

Expand All @@ -276,31 +276,31 @@
'fa' => function ($expression) {
$expression = Util::parse($expression);

return '<i class="fa fa-'.Util::strip($expression->get(0)).' '.Util::strip($expression->get(1)).'"></i>';
return '<i class="fa fa-' . Util::strip($expression->get(0)) . ' ' . Util::strip($expression->get(1)) . '"></i>'; // phpcs:ignore
},

'fas' => function ($expression) {
$expression = Util::parse($expression);

return '<i class="fas fa-'.Util::strip($expression->get(0)).' '.Util::strip($expression->get(1)).'"></i>';
return '<i class="fas fa-' . Util::strip($expression->get(0)) . ' ' . Util::strip($expression->get(1)) . '"></i>'; // phpcs:ignore
},

'far' => function ($expression) {
$expression = Util::parse($expression);

return '<i class="far fa-'.Util::strip($expression->get(0)).' '.Util::strip($expression->get(1)).'"></i>';
return '<i class="far fa-' . Util::strip($expression->get(0)) . ' ' . Util::strip($expression->get(1)) . '"></i>'; // phpcs:ignore
},

'fal' => function ($expression) {
$expression = Util::parse($expression);

return '<i class="fal fa-'.Util::strip($expression->get(0)).' '.Util::strip($expression->get(1)).'"></i>';
return '<i class="fal fa-' . Util::strip($expression->get(0)) . ' ' . Util::strip($expression->get(1)) . '"></i>'; // phpcs:ignore
},

'fab' => function ($expression) {
$expression = Util::parse($expression);

return '<i class="fab fa-'.Util::strip($expression->get(0)).' '.Util::strip($expression->get(1)).'"></i>';
return '<i class="fab fa-' . Util::strip($expression->get(0)) . ' ' . Util::strip($expression->get(1)) . '"></i>'; // phpcs:ignore
},

];
Loading

0 comments on commit 476c3fd

Please sign in to comment.