From 5c6c78f816709a5a6858352233de8c3f61bfe8d0 Mon Sep 17 00:00:00 2001 From: Brian Matovu Date: Sat, 30 Jan 2021 11:01:35 +0300 Subject: [PATCH] Initial commit --- .editorconfig | 19 ++++++ .gitattributes | 16 +++++ .gitignore | 8 +++ .php_cs | 84 +++++++++++++++++++++++++ .scrutinizer.yml | 35 +++++++++++ .styleci.yml | 18 ++++++ .travis.yml | 57 +++++++++++++++++ composer.json | 66 +++++++++++++++++++ config/hello-world.php | 5 ++ doctum.php | 38 +++++++++++ license.txt | 21 +++++++ phpunit.xml.dist | 29 +++++++++ readme.md | 73 +++++++++++++++++++++ src/HelloWorld.php | 18 ++++++ src/HelloWorldFacade.php | 23 +++++++ src/HelloWorldServiceProvider.php | 38 +++++++++++ tests/HelloWorldFacadeTest.php | 15 +++++ tests/HelloWorldServiceProviderTest.php | 18 ++++++ tests/HelloWorldTest.php | 21 +++++++ tests/TestCase.php | 36 +++++++++++ 20 files changed, 638 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .php_cs create mode 100644 .scrutinizer.yml create mode 100644 .styleci.yml create mode 100644 .travis.yml create mode 100644 composer.json create mode 100644 config/hello-world.php create mode 100644 doctum.php create mode 100644 license.txt create mode 100644 phpunit.xml.dist create mode 100644 readme.md create mode 100644 src/HelloWorld.php create mode 100644 src/HelloWorldFacade.php create mode 100644 src/HelloWorldServiceProvider.php create mode 100644 tests/HelloWorldFacadeTest.php create mode 100644 tests/HelloWorldServiceProviderTest.php create mode 100644 tests/HelloWorldTest.php create mode 100644 tests/TestCase.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7c84b41 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +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 + +[*.{json,yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b4b276a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Uncomment the lines below for your package; +# These are basically files you don't want in a release. + +# /.editorconfig export-ignore +# /.gitattributes export-ignore +# /.gitignore export-ignore +# /.php_cs export-ignore +# /.sami.dist export-ignore +# /.scrutinizer.yml export-ignore +# /.styleci.yml export-ignore +# /.travis.yml export-ignore +# /phpunit.xml.dist export-ignore +# /tests export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd50dee --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.idea +.php_cs.cache +.phpunit.result.cache +composer.lock +coverage +coverage.clover +docs +vendor diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..69ca28f --- /dev/null +++ b/.php_cs @@ -0,0 +1,84 @@ + true, + + // Arrays + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'trim_array_spaces' => true, + 'no_whitespace_before_comma_in_array' => true, + 'whitespace_after_comma_in_array' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'trailing_comma_in_multiline_array' => true, + 'not_operator_with_successor_space' => true, + + // General + 'indentation_type' => true, + 'single_quote' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_extra_blank_lines' => true, + 'no_whitespace_in_blank_line' => true, + 'linebreak_after_opening_tag' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'cast_spaces' => true, + 'concat_space' => [ + 'spacing' => 'none', + ], + 'blank_line_before_statement' => true, + 'method_chaining_indentation' => true, + 'ordered_imports' => [ + 'sort_algorithm' => 'alpha', + ], + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], + 'return_type_declaration' => [ + 'space_before' => 'none', + ], + + // Docs + 'phpdoc_types' => true, + 'phpdoc_indent' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_align' => true, + 'phpdoc_summary' => true, + 'phpdoc_separation' => true, + 'phpdoc_scalar' => true, + 'phpdoc_order' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_var_without_name' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => false, + ], +]; + +$excludes = [ + 'coverage', + 'docs', + 'vendor', +]; + +return PhpCsFixer\Config::create() + ->setRules($rules) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude($excludes) + ->in(__DIR__.'/config') + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ->ignoreDotFiles(true) + ->ignoreVCS(true) + ); diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..a2e4ca6 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,35 @@ +# Code style +# https://scrutinizer-ci.com/docs/reviews/configure_automated_checks +checks: + php: true + +filter: + excluded_paths: + - "docs/" + - "tests/" + +# Tessts +# https://scrutinizer-ci.com/docs/configuration/build_reference + +# build: +# environment: +# php: +# version: '7.2' +# requires: +# - branch: master +# nodes: +# analysis: +# tests: +# override: +# - php-scrutinizer-run + +# Analysis +# https://scrutinizer-ci.com/docs/tools/external-code-coverage/ + +tools: + external_code_coverage: true + +# Code Style +# https://scrutinizer-ci.com/docs/configuration/coding_style + +coding_style: diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..404993a --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,18 @@ +preset: laravel + +disabled: + - single_class_element_per_statement + +# https://docs.styleci.io/standalone-php#risky +risky: false + +finder: + exclude: + - "config" + - "coverage" + - "database" + - "docs" + - "tests" + - "vendor" + name: + - "*.php" diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..886f826 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,57 @@ +language: php + +cache: + directories: + - $HOME/.composer/cache/files + +# https://docs.travis-ci.com/user/build-stages + +jobs: + + include: + + - stage: test + + php: 7.2 + + install: + - wget https://scrutinizer-ci.com/ocular.phar + + before_script: + - travis_retry composer self-update + - travis_retry composer update --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts + + script: + - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover + + after_script: + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + + - stage: deploy + + name: "Documentation" + + if: branch = master + + php: 7.2 + + before_script: + - git clone https://github.com/mtvbrianking/laravel-package-boilerplate.git + + script: + - vendor/bin/doctum.php update doctum.php + + # https://docs.travis-ci.com/user/deployment/pages/ + deploy: + provider: pages + skip-cleanup: true + github-token: $GITHUB_TOKEN + local_dir: docs + on: + branch: master + +# https://docs.travis-ci.com/user/notifications +notifications: + email: + on_success: never + on_failure: always diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..02ca2e8 --- /dev/null +++ b/composer.json @@ -0,0 +1,66 @@ +{ + "name": "bmatovu/laravel-package-boilerplate", + "description": "Laravel package boilerplate.", + "homepage": "https://github.com/mtvbrianking/laravel-package-boilerplate", + "type": "project", + "license": "MIT", + "keywords": [ + "laravel", + "lumen", + "package", + "development", + "starter", + "boilerplate" + ], + "authors": [ + { + "name": "Brian Matovu", + "email": "mtvbrianking@gmail.com", + "homepage": "http://bmatovu.com", + "role": "Developer" + } + ], + "require": { + "php": "^7.2.5|^8.0", + "illuminate/support": "^6.0|^7.0|^8.0" + }, + "require-dev": { + "code-lts/doctum": "^5.3", + "friendsofphp/php-cs-fixer": "^2.18", + "illuminate/container": "^6.0|^7.0|^8.0", + "orchestra/testbench": "^4.0|^5.0|^6.0", + "phpunit/phpunit": "^8.0|^9.0" + }, + "autoload": { + "psr-4": { + "Bmatovu\\HelloWorld\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Bmatovu\\HelloWorld\\Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "cs-fix": "php-cs-fixer fix", + "cs-lint": "php-cs-fixer fix --dry-run", + "doc": "doctum.php update doctum.php", + "test": "phpunit", + "test-coverage": "phpunit --coverage-html coverage" + }, + "config": { + "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Bmatovu\\HelloWorld\\HelloWorldServiceProvider" + ], + "aliases": { + "HelloWorld": "Bmatovu\\HelloWorld\\HelloWorldFacade" + } + } + } +} diff --git a/config/hello-world.php b/config/hello-world.php new file mode 100644 index 0000000..93c4e95 --- /dev/null +++ b/config/hello-world.php @@ -0,0 +1,5 @@ +files() + ->name('*.php') + ->exclude('tests') + ->exclude('vendor') + ->in($dir); + +$versions = GitVersionCollection::create($dir) + ->add('master', 'Master branch'); + +$repo = new GitHubRemoteRepository( + 'mtvbrianking/laravel-package-boilerplate', + dirname($dir), + 'https://github.com/' +); + +$options = [ + 'theme' => 'default', + 'versions' => $versions, + 'title' => 'Laravel Package Boilerplate', + 'build_dir' => __DIR__.'/docs', + 'cache_dir' => __DIR__.'/docs/cache', + 'remote_repository' => $repo, + 'default_opened_level' => 3, +]; + +return new Doctum($iterator, $options); diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..35792b9 --- /dev/null +++ b/license.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8e7fba5 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + tests + + + + + src/ + + + + + + + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..50e8695 --- /dev/null +++ b/readme.md @@ -0,0 +1,73 @@ +## Laravel Package Boilerplate. + +[![Build Status](https://travis-ci.org/mtvbrianking/laravel-package-boilerplate.svg?branch=master)](https://travis-ci.org/mtvbrianking/laravel-package-boilerplate) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mtvbrianking/laravel-package-boilerplate/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mtvbrianking/laravel-package-boilerplate/?branch=master) +[![Code Coverage](https://scrutinizer-ci.com/g/mtvbrianking/laravel-package-boilerplate/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mtvbrianking/laravel-package-boilerplate/?branch=master) +[![StyleCI](https://github.styleci.io/repos/230607368/shield?branch=master)](https://github.styleci.io/repos/230607368) +[![Documentation](https://img.shields.io/badge/Documentation-Blue)](https://mtvbrianking.github.io/laravel-package-boilerplate) + +### [Installation](https://packagist.org/packages/bmatovu/laravel-package-boilerplate) + +Install via composer package manager: + +```bash +composer create-project --prefer-dist bmatovu/laravel-package-boilerplate hello-world +``` + +Alternatively, generate a Github repository using the `Use this template` call to action button or the link below... + +> https://github.com/mtvbrianking/laravel-package-boilerplate/generate + +### Own the package + +Update the `composer.json` file to match your credentials. + +Change the namespaces to match those you're using in `src`. + +Change the type from `project` to `library` + +```bash +composer dump-autoload +``` + +## Testing + +We've defaulted to [Orchestra's testbench](https://github.com/orchestral/testbench) + +```bash +composer test +``` + +### Code Style & Quality + +We've added [StyleCI](https://styleci.io) configurations with the Laravel present to get you started. + +Also added [ScrutinizerCI](https://scrutinizer-ci.com) configurations for code quality, test coverage inspection. + +Locally, you can restort to [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). + +```bash +composer cs-fix +``` + +### Source code documentation + +You need to download [Doctum](https://github.com/code-lts/doctum) for source code documentation. + +```bash +composer doc +``` + +To auto deploy documentation; be sure to add a [`Github token`](https://github.com/settings/tokens) for authorization. + +### Sharing the package + +You may share your package via [Packagist](packagist.org) + +## Useful resources + +- [Laravel Package Development - Blog](https://laravelpackage.com) + +- [Laravel Package Development - Documentation](https://laravel.com/docs/master/packages) + +- [Travis CI + GitHub Pages - Automated deployment](https://www.youtube.com/watch?v=BFpSD2eoXUk) diff --git a/src/HelloWorld.php b/src/HelloWorld.php new file mode 100644 index 0000000..01e4d1a --- /dev/null +++ b/src/HelloWorld.php @@ -0,0 +1,18 @@ +app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../config/hello-world.php' => base_path('config/hello-world.php'), + ], 'config'); + + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + } + } + + /** + * Register the application services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__.'/../config/hello-world.php', 'hello-world'); + + $this->app->bind('hello-world', function () { + return new HelloWorld(); + }); + } +} diff --git a/tests/HelloWorldFacadeTest.php b/tests/HelloWorldFacadeTest.php new file mode 100644 index 0000000..aa815c7 --- /dev/null +++ b/tests/HelloWorldFacadeTest.php @@ -0,0 +1,15 @@ +assertEquals('Hello Dummy.', $greeting); + } +} diff --git a/tests/HelloWorldServiceProviderTest.php b/tests/HelloWorldServiceProviderTest.php new file mode 100644 index 0000000..683741c --- /dev/null +++ b/tests/HelloWorldServiceProviderTest.php @@ -0,0 +1,18 @@ +make('hello-world'); + + $this->assertInstanceOf(HelloWorld::class, $helloWorld); + } +} diff --git a/tests/HelloWorldTest.php b/tests/HelloWorldTest.php new file mode 100644 index 0000000..ec4cd4b --- /dev/null +++ b/tests/HelloWorldTest.php @@ -0,0 +1,21 @@ +greet(); + + $this->assertEquals('Hello World.', $greeting); + + $greeting = $helloWorld->greet('Dummy'); + + $this->assertEquals('Hello Dummy.', $greeting); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..4a0d71a --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,36 @@ + 'Bmatovu\HelloWorld\HelloWorldFacade', + ]; + } +}