Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler CI & Contributing #41

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea
vendor
composer.lock
.phpunit.result.cache
build
19 changes: 0 additions & 19 deletions .php_cs

This file was deleted.

19 changes: 0 additions & 19 deletions .scrutinizer.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .styleci.yml

This file was deleted.

2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**!
12 changes: 0 additions & 12 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
122 changes: 122 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Laravel Timezone" default="build" basedir=".">
<property name="project.bindir" value="${project.basedir}/vendor/bin" />
<property name="project.builddir" value="${project.basedir}/build" />

<target name="build">
<phingcall target="lint" />
<phingcall target="tests" />
<phingcall target="style" />
<phingcall target="calisthenics" />
</target>

<target name="lint">
<phplint haltonfailure="true">
<fileset dir="${project.basedir}/src">
<include name="**/*.php" />
</fileset>
<fileset dir="${project.basedir}/tests">
<include name="**/*.php" />
</fileset>
</phplint>
</target>

<target name="tests">
<exec command="${project.bindir}/phpunit --testsuite Unit" passthru="true" checkreturn="true" />
</target>

<target name="style">
<exec executable="${project.bindir}/phpcs" passthru="true" checkreturn="true" >
<arg value="--standard=PSR2" />
<arg value="${project.basedir}/src" />
<arg value="${project.basedir}/tests" />
</exec>
</target>

<target name="calisthenics">
<exec executable="${project.bindir}/ecs" passthru="true" checkreturn="true" >
<arg value="check" />
<arg value="${project.basedir}/src" />
<arg value="${project.basedir}/tests" />
</exec>
</target>

<target name="qa" depends="prepare-ci">
<phingcall target="tests-ci" />
<phingcall target="loc-ci" />
<phingcall target="dependencies-ci" />
<phingcall target="phpmd-ci" />
<phingcall target="style-ci" />
<phingcall target="duplications-ci" />
</target>

<target name="prepare-ci">
<delete dir="${project.builddir}/logs" />
<delete dir="${project.builddir}/coverage" />
<delete dir="${project.builddir}/images" />

<mkdir dir="${project.builddir}/logs" mode="0777" />
<mkdir dir="${project.builddir}/coverage" mode="0777" />
<mkdir dir="${project.builddir}/images" mode="0777" />
</target>

<target name="tests-ci">
<exec executable="${project.bindir}/phpunit" passthru="true">
<arg value="--coverage-html" />
<arg value="${project.builddir}/coverage" />
<arg value="--coverage-clover" />
<arg value="${project.builddir}/logs/clover.xml" />
<arg value="--log-junit" />
<arg value="${project.builddir}/logs/junit.xml" />
</exec>
</target>

<target name="loc-ci">
<exec executable="${project.bindir}/phploc" passthru="true">
<arg value="--count-tests" />
<arg value="--log-csv" />
<arg value="${project.builddir}/logs/phploc.csv" />
<arg value="--log-xml" />
<arg value="${project.builddir}/logs/phploc.xml" />
<arg value="${project.basedir}/src" />
<arg value="${project.basedir}/tests" />
</exec>
</target>

<target name="dependencies-ci">
<exec executable="${project.bindir}/pdepend" passthru="true">
<arg value="--jdepend-xml=${project.builddir}/logs/jdepend.xml" />
<arg value="--jdepend-chart=${project.builddir}/images/dependencies.svg" />
<arg value="--overview-pyramid=${project.builddir}/images/overview-pyramid.svg" />
<arg path="${project.basedir}/src" />
</exec>
</target>

<target name="phpmd-ci">
<exec executable="${project.bindir}/phpmd" passthru="true">
<arg path="${project.basedir}/src" />
<arg value="xml" />
<arg value="cleancode,codesize,controversial,design,naming,unusedcode" />
<arg value="--reportfile" />
<arg value="${project.builddir}/logs/pmd.xml" />
</exec>
</target>

<target name="style-ci">
<exec executable="${project.bindir}/phpcs" passthru="true">
<arg value="--report=checkstyle" />
<arg value="--report-file=${project.builddir}/logs/checkstyle.xml" />
<arg value="--standard=PSR2" />
<arg value="${project.basedir}/src" />
<arg value="${project.basedir}/tests" />
</exec>
</target>

<target name="duplications-ci">
<exec executable="${project.bindir}/phpcpd" passthru="true">
<arg value="--log-pmd" />
<arg value="${project.builddir}/logs/pmd-cpd.xml" />
<arg path="${project.basedir}/src" />
</exec>
</target>
</project>
26 changes: 23 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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"
]
}
}
32 changes: 32 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
@@ -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'
21 changes: 21 additions & 0 deletions githooks/README.md
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 4 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo 'Phing'
./vendor/bin/phing || exit 1
4 changes: 4 additions & 0 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo 'Phing QA'
./vendor/bin/phing qa || exit 1
5 changes: 5 additions & 0 deletions phpspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
suites:
main:
namespace: JamesMills\LaravelTimezone
psr4_prefix: JamesMills\LaravelTimezone\
src_path: src
30 changes: 30 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/config</directory>
<!-- <directory suffix=".php">./src/Facades</directory>-->
<!-- <directory suffix=".php">./src/Listeners</directory>-->
<!-- <directory suffix=".php">./src/Providers</directory>-->
</exclude>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
</php>
</phpunit>
2 changes: 0 additions & 2 deletions src/Listeners/Auth/UpdateUsersTimezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function handle($event)
*/
if ($event instanceof AccessTokenCreated) {
Auth::loginUsingId($event->userId);

return;
}

Expand All @@ -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);
}
}
Expand Down
Loading