Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed May 23, 2021
0 parents commit aaa8f56
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore

/docker-compose.yml export-ignore
/tests export-ignore

/phpstan.neon export-ignore
/.php_cs.php export-ignore
/psalm.xml export-ignore
/phpunit.xml export-ignore
/check export-ignore
/coverage export-ignore
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_CS_FIXER_IGNORE_ENV: 1
MYSQL_PORT: 3307
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
push:
pull_request:
branches: [ master ]

jobs:
phpunit:
name: Tests (PHPUnit)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Start docker containers
run: docker-compose up -d
- name: Install composer dependencies
run: composer install
- name: Run tests
run: vendor/bin/phpunit

steps:
- uses: actions/checkout@v2
- name: Install composer dependencies
run: composer install
- name: Run psalm
run: vendor/bin/psalm

phpstan:
name: Static analysis (PHPStan)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install composer dependencies
run: composer install
- name: Run phpstan
run: vendor/bin/phpstan analyse

php-cs-fixer:
name: Code style (php-cs-fixer)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install php-cs-fixer
run: composer global require friendsofphp/php-cs-fixer
- name: Run php-cs-fixer
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php_cs.php
- name: Commit changes from php-cs-fixer
uses: EndBug/add-and-commit@v5
with:
author_name: "PHP CS Fixer"
author_email: "[email protected]"
message: Fix code style (php-cs-fixer)
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.phpunit.result.cache
package-lock.json
composer.lock
vendor/
.php_cs.cache
.vscode/
coverage/
node_modules
144 changes: 144 additions & 0 deletions .php_cs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$rules = [
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => null,
'|' => 'no_space',
]
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_superfluous_phpdoc_tags' => true,
'blank_line_before_statement' => [
'statements' => ['return']
],
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => [
'elements' => ['method']
],
'class_definition' => true,
'concat_space' => [
'spacing' => 'one'
],
'declare_equal_normalize' => true,
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'declare_strict_types' => true,
'fully_qualified_strict_types' => true, // added by Shift
'function_declaration' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'increment_style' => ['style' => 'post'],
'indentation_type' => true,
'linebreak_after_opening_tag' => true,
'line_ending' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true, // added from Symfony
'magic_method_casing' => true, // added from Symfony
'magic_constant_casing' => true,
'method_argument_space' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'use',
'use_trait',
]
],
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [
'use' => 'echo'
],
'no_multiline_whitespace_around_double_arrow' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line'
],
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'psr4' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false, // disabled by Shift
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'no_unused_imports' => true,
'single_line_comment_style' => [
'comment_types' => ['hash']
],
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
];

$project_path = getcwd();
$finder = Finder::create()
->in([
$project_path . '/src',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return Config::create()
->setFinder($finder)
->setRules($rules)
->setRiskyAllowed(true)
->setUsingCache(true);
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# REPLACE

Simple and flexible package template.

# Usage

- Replace all occurances of `REPLACE` (case sensitive) with the name of the package namespace. E.g. the `Foo` in `ArchTech\Foo`.
- Replace all occurances of `replace2` with the name of the package on composer, e.g. the `bar` in `archtechx/bar`.
- If MySQL is not needed, remove `docker-compose.yml`, remove the line that runs docker from `./check`, and set `DB_CONNECTION` in `phpunit.xml` to `sqlite`, and `DB_DATABASE` to `:memory:`.

---

## Installation

```sh
composer require stancl/replace2
```

## Usage

```php
// ...
```

## Development

Running all checks locally:

```sh
./check
```

Running tests:

```sh
MYSQL_PORT=3307 docker-compose up -d

phpunit
```

Code style will be automatically fixed by php-cs-fixer.
56 changes: 56 additions & 0 deletions check
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -e

offer_run() {
read -p "For more output, run $1. Run it now (Y/n)? " run

case ${run:0:1} in
n|N )
exit 1
;;
* )
$1
;;
esac

exit 1
}

if (php-cs-fixer fix --dry-run --config=.php_cs.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
read -p "⚠️ php-cs-fixer found issues. Fix (Y/n)? " fix
case ${fix:0:1} in
n|N )
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php_cs.php'
;;
* )
if (php-cs-fixer fix --config=.php_cs.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php_cs.php'
fi
;;
esac
fi

if (./vendor/bin/phpstan analyse > /dev/null 2>/dev/null); then
echo '✅ PHPStan OK'
else
echo '❌ PHPStan FAIL'
offer_run './vendor/bin/phpstan analyse'
fi

(MYSQL_PORT=3307 docker-compose up -d > /dev/null 2>/dev/null) || true

if (./vendor/bin/pest > /dev/null 2>/dev/null); then
echo '✅ PEST OK'
else
echo '❌ PEST FAIL'
offer_run './vendor/bin/pest'
fi

echo '=================='
echo '✅ Everything OK'
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "archtechx/replace",
"description": "",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Samuel Štancl",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"ArchTech\\REPLACE\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ArchTech\\REPLACE\\Tests\\": "tests/"
}
},
"require": {
"illuminate/support": "^8.24"
},
"require-dev": {
"orchestra/testbench": "^6.9",
"vimeo/psalm": "^4.2",
"nunomaduro/larastan": "^0.6.10",
"pestphp/pest": "^1.2",
"pestphp/pest-plugin-laravel": "^1.0"
},
"extra": {
"laravel": {
"providers": [
"ArchTech\\REPLACE\\PackageServiceProvider"
]
}
}
}
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: main
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_TCP_PORT: ${MYSQL_PORT}
ports:
- "${MYSQL_PORT}:${MYSQL_PORT}"
Loading

0 comments on commit aaa8f56

Please sign in to comment.