diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..6f313c6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.yml]
+indent_size = 2
diff --git a/.gitignore b/.gitignore
index 27e8277..99a561c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
.idea
vendor
composer.lock
+.phpunit.result.cache
+build
diff --git a/.php_cs b/.php_cs
deleted file mode 100644
index 9df3aab..0000000
--- a/.php_cs
+++ /dev/null
@@ -1,19 +0,0 @@
-in(__DIR__ . '/src')
-;
-
-return PhpCsFixer\Config::create()
- ->setUsingCache(false)
- ->setRules([
- '@PSR2' => true,
- 'concat_space' => ['spacing' => 'one'],
- 'cast_spaces' => ['space' => 'single'],
- 'no_unused_imports' => true,
- 'blank_line_before_statement' => true,
- 'trailing_comma_in_multiline_array' => true,
- 'single_quote' => true
- ])
- ->setFinder($finder)
-;
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index df16b68..0000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-filter:
- excluded_paths: [tests/*]
-
-checks:
- php:
- remove_extra_empty_lines: true
- remove_php_closing_tag: true
- remove_trailing_whitespace: true
- fix_use_statements:
- remove_unused: true
- preserve_multiple: false
- preserve_blanklines: true
- order_alphabetically: true
- fix_php_opening_tag: true
- fix_linefeed: true
- fix_line_ending: true
- fix_identation_4spaces: true
- fix_doc_comments: true
-
diff --git a/.styleci.yml b/.styleci.yml
deleted file mode 100644
index f4d3cbc..0000000
--- a/.styleci.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-preset: laravel
-
-disabled:
- - single_class_element_per_statement
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9af19f3..796f18a 100755
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -50,4 +50,6 @@ If the project maintainer has any additional requirements, you will find them li
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
+- **[Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)** - Make sure to add our [Git Hooks](githooks/README.md), this will ensure your commit it will be always compliant to our requirements.
+
**Happy coding**!
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 39b681e..0000000
--- a/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-THIS := $(realpath $(lastword $(MAKEFILE_LIST)))
-HERE := $(shell dirname $(THIS))
-
-.PHONY: fix lint test
-
-fix:
- $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs
-
-lint:
- $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs --dry-run
-
-test: lint
diff --git a/README.md b/README.md
index 03b9416..645078b 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ composer require jamesmills/laravel-timezone
Publish database migrations
```
-php artisan vendor:publish --provider="JamesMills\LaravelTimezone\LaravelTimezoneServiceProvider" --tag=migrations
+php artisan vendor:publish --provider="JamesMills\LaravelTimezone\Providers\LaravelTimezoneServiceProvider" --tag=migrations
```
Run the database migrations. This will add a `timezone` column to your `users` table.
@@ -106,7 +106,7 @@ $post = Post::create([
Publishing the config file is optional.
```php
-php artisan vendor:publish --provider="JamesMills\LaravelTimezone\LaravelTimezoneServiceProvider" --tag=config
+php artisan vendor:publish --provider="JamesMills\LaravelTimezone\Providers\LaravelTimezoneServiceProvider" --tag=config
```
### Flash Messages
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..b85c322
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index 5470dfa..fc00c4b 100644
--- a/composer.json
+++ b/composer.json
@@ -18,6 +18,18 @@
"torann/geoip": "^1.0",
"nesbot/carbon": "^1.0 || ^2.0"
},
+ "require-dev": {
+ "phpunit/phpunit": "^8.5",
+ "phing/phing": "^2.16",
+ "pdepend/pdepend": "^2.6",
+ "phploc/phploc": "^5.0",
+ "phpmd/phpmd": "^2.8",
+ "sebastian/phpcpd": "^4.1",
+ "squizlabs/php_codesniffer": "^3.5",
+ "symplify/easy-coding-standard": "^7.2",
+ "object-calisthenics/phpcs-calisthenics-rules": "^3.7",
+ "phpspec/phpspec": "^6.1"
+ },
"autoload": {
"psr-4": {
"JamesMills\\LaravelTimezone\\": "src/",
@@ -28,11 +40,19 @@
"extra": {
"laravel": {
"providers": [
- "JamesMills\\LaravelTimezone\\LaravelTimezoneServiceProvider"
+ "JamesMills\\LaravelTimezone\\Providers\\LaravelTimezoneServiceProvider"
]
}
},
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^2.12"
+ "scripts": {
+ "test": [
+ "phing"
+ ],
+ "test:ci": [
+ "phing qa"
+ ],
+ "git-hooks": [
+ "rsync -av --exclude='*.md' ./githooks/ ./.git/hooks"
+ ]
}
}
diff --git a/ecs.yaml b/ecs.yaml
new file mode 100644
index 0000000..5cf4495
--- /dev/null
+++ b/ecs.yaml
@@ -0,0 +1,32 @@
+services:
+ ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff:
+ maxNestingLevel: 2
+
+ ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff: ~
+
+ ObjectCalisthenics\Sniffs\CodeAnalysis\OneObjectOperatorPerLineSniff:
+ variablesHoldingAFluentInterface: ["$queryBuilder", "$containerBuilder", "$request"]
+ methodsStartingAFluentInterface: ["createQueryBuilder", "make", "command", "skip"]
+ methodsEndingAFluentInterface: ["execute", "getQuery"]
+
+ ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff:
+ minLength: 3
+ allowedShortNames: ["i", "id", "to", "up", "ip"]
+
+ ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff:
+ maxLength: 300
+
+ ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff:
+ maxLength: 40
+
+ ObjectCalisthenics\Sniffs\Metrics\PropertyPerClassLimitSniff:
+ maxCount: 10
+
+ ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff:
+ maxCount: 15
+
+# ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: ~
+
+ ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff:
+ allowedClasses:
+ - '*\DataObject'
diff --git a/githooks/README.md b/githooks/README.md
new file mode 100644
index 0000000..509db87
--- /dev/null
+++ b/githooks/README.md
@@ -0,0 +1,21 @@
+# Git Hooks
+
+Just copy all file into your `.git/hooks` folder.
+
+Ensure they have permissions to be executed `chmod +x`.
+
+## pre-commit
+
+On the root folder `cp githooks/pre-commit .git/hooks/pre-commit`
+
+Before each commit it'll run the `make fix` & `phing` verification
+
+## pre-push
+
+On the root folder `cp githooks/pre-push .git/hooks/pre-push`
+
+Before each push it'll run the `phing qa` verification
+
+## Copying all to Git Hooks
+
+On the root folder `composer git-hooks`
diff --git a/githooks/pre-commit b/githooks/pre-commit
new file mode 100755
index 0000000..faf03f2
--- /dev/null
+++ b/githooks/pre-commit
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo 'Phing'
+./vendor/bin/phing || exit 1
diff --git a/githooks/pre-push b/githooks/pre-push
new file mode 100755
index 0000000..a806f0b
--- /dev/null
+++ b/githooks/pre-push
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo 'Phing QA'
+./vendor/bin/phing qa || exit 1
diff --git a/phpspec.yml b/phpspec.yml
new file mode 100644
index 0000000..f9bbc7a
--- /dev/null
+++ b/phpspec.yml
@@ -0,0 +1,5 @@
+suites:
+ main:
+ namespace: JamesMills\LaravelTimezone
+ psr4_prefix: JamesMills\LaravelTimezone\
+ src_path: src
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..28d2d3a
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,30 @@
+
+
+
+
+ ./tests
+
+
+
+
+ ./src
+
+ ./src/config
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Listeners/Auth/UpdateUsersTimezone.php b/src/Listeners/Auth/UpdateUsersTimezone.php
index 7e3eac1..24f071b 100644
--- a/src/Listeners/Auth/UpdateUsersTimezone.php
+++ b/src/Listeners/Auth/UpdateUsersTimezone.php
@@ -29,7 +29,6 @@ public function handle($event)
*/
if ($event instanceof AccessTokenCreated) {
Auth::loginUsingId($event->userId);
-
return;
}
@@ -54,7 +53,6 @@ public function handle($event)
if (config('timezone.overwrite') == true || $user->timezone == null) {
$user->timezone = $geoip_info['timezone'];
$user->save();
-
$this->notify($geoip_info);
}
}
diff --git a/src/LaravelTimezoneServiceProvider.php b/src/Providers/LaravelTimezoneServiceProvider.php
similarity index 76%
rename from src/LaravelTimezoneServiceProvider.php
rename to src/Providers/LaravelTimezoneServiceProvider.php
index e20f239..7237eea 100644
--- a/src/LaravelTimezoneServiceProvider.php
+++ b/src/Providers/LaravelTimezoneServiceProvider.php
@@ -1,12 +1,13 @@
publishes([
- __DIR__ . '/database/migrations/add_timezone_column_to_users_table.php.stub' => database_path('/migrations/' . date('Y_m_d_His') . '_add_timezone_column_to_users_table.php'),
- ], 'migrations');
+ $this->publishes($this->migrationHandler(), 'migrations');
}
// Register the Timezone alias
@@ -51,13 +50,17 @@ function ($expression) {
if (count($options) == 1) {
return "";
- } elseif (count($options) == 2) {
+ }
+
+ if (count($options) == 2) {
return "";
- } elseif (count($options) == 3) {
+ }
+
+ if (count($options) == 3) {
return "";
- } else {
- return 'error';
}
+
+ return 'error';
}
);
}
@@ -89,4 +92,17 @@ private function registerEventListener(): void
Event::listen($events, UpdateUsersTimezone::class);
}
+
+ /**
+ * @return array
+ */
+ private function migrationHandler(): array
+ {
+ $from = __DIR__ . '/database/migrations/add_timezone_column_to_users_table.php.stub';
+ $to = database_path('/migrations/' . date('Y_m_d_His') . '_add_timezone_column_to_users_table.php');
+
+ return [
+ $from => $to,
+ ];
+ }
}
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..8f4803c
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,3 @@
+*
+!public/
+!.gitignore