Skip to content

Commit

Permalink
feat: Scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Dec 22, 2023
1 parent 396f0f5 commit 036ff9a
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ phpctl sh echo 'Hello, World!' # To run arbitrary sh commands inside the contain
| `php-cs-fixer` | Runs PHP-CS-Fixer. |

### Scaffolders
| Command | Description |
| --- | --- |
| `init-phpunit` | Initializes a PHPUnit configuration. |
| Command | Description |
|----------------------------|---------------------------------------------------------------|
| `create [framework] [dir]` | Creates a new project using the given framework (or package). |
| `init [skeleton]` | Initializes a skeleton configuration. |

#### Skeletons
- `phpunit`
- `php-cs-fixer`

### Helpers
| Command | Description |
Expand Down
106 changes: 106 additions & 0 deletions skeletons/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);
/**
* This file is part of Project.
*
* @link https://project.com
* @document https://docs.project.com
* @contact [email protected]
* @license LICENSE.md
*/
$header = <<<'EOF'
This file is part of Project.
@link https://project.com
@document https://docs.project.com
@contact [email protected]
@license LICENSE.md
EOF;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
'separate' => 'none',
'location' => 'after_declare_strict',
],
'array_syntax' => [
'syntax' => 'short',
],
'list_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => null,
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author',
],
],
'ordered_imports' => [
'imports_order' => [
'class', 'function', 'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'single_line_empty_body' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('public')
->exclude('runtime')
->exclude('vendor')
->in(__DIR__)
)
->setUsingCache(true);
File renamed without changes.
3 changes: 2 additions & 1 deletion src/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ help() {
echo -e "\033[0;32m sh [commands] \033[0m Starts an interactive Shell session or runs sh commands"
echo -e "\033[0;32m repl \033[0m Starts a PHP REPL session (powered by PsySH)"
echo -e "\033[0;32m php-cs-fixer \033[0m Runs PHP-CS-Fixer"
echo -e "\033[0;32m init-phpunit \033[0m Initializes a PHPUnit configuration"
echo -e "\033[0;32m create [framework] [dir] \033[0m Creates a new project using the given framework (or package)"
echo -e "\033[0;32m init [skeleton] \033[0m Initializes a skeleton configuration (phpunit, php-cs-fixer)"
echo -e "\033[0;32m help or man \033[0m Displays this help message"
echo -e "\033[0;32m doctor \033[0m Inspects the current PHP_VERSION and PHPCTL_IMAGE"
echo -e "\033[0;32m build \033[0m Builds the current Dockerfile (useful for custom images)"
Expand Down
37 changes: 37 additions & 0 deletions src/scaffold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
create() {
package_alias="$1"
case "$package_alias" in
"hyperf")
package="hyperf/hyperf-skeleton"
;;
"laravel")
package="laravel/laravel"
;;
"symfony")
package="symfony/skeleton"
;;
*)
package="$package_alias"
;;
esac

run -- composer create-project "$package" "$2"
}

init() {
skeleton_alias="$1"
case "$skeleton_alias" in
"phpunit")
skeleton="phpunit.xml"
;;
"php-cs-fixer")
skeleton=".php-cs-fixer.php"
;;
*)
echo -e "\033[0;31mSkeleton ($skeleton_alias) not handled.\033[0m"
exit 1
esac

cp "$PHPCTL_DIR/skeletons/$skeleton" "$skeleton"
echo -e "\033[0;32m$skeleton created!\033[0m"
}

0 comments on commit 036ff9a

Please sign in to comment.