Skip to content

Commit 839e3ba

Browse files
Mass cleanup, move to PHP 7.0 minimum, github actions (#19)
1 parent e47d18e commit 839e3ba

File tree

95 files changed

+1465
-1299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1465
-1299
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}
14+
runs-on: ${{ matrix.operating-system }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
operating-system: [ubuntu-latest]
19+
# TODO: Upgrade PHPUnit to support testing on PHP 8, will require bumping minimum
20+
# php-versions: ['7.3', '7.4', '8.0']
21+
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Setup PHP, with composer and extensions
28+
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
29+
with:
30+
php-version: ${{ matrix.php-versions }}
31+
coverage: pcov
32+
tools: composer:v2
33+
env:
34+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Get composer cache directory
37+
id: composercache
38+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
39+
40+
- name: Setup problem matchers
41+
run: |
42+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
43+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v2
47+
with:
48+
path: ${{ steps.composercache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
50+
restore-keys: ${{ runner.os }}-composer-
51+
52+
- name: Install Composer dependencies
53+
run: composer install --prefer-dist
54+
55+
- name: Test with phpunit
56+
run: composer test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
2+
.php_cs.cache
13
composer.lock
24
composer.phar
35
coverage/

.php_cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
$rules = [
3+
'@PSR2' => true,
4+
// additional rules
5+
'array_syntax' => ['syntax' => 'short'],
6+
'binary_operator_spaces' => [
7+
'default' => 'single_space',
8+
'operators' => [
9+
'=>' => 'align_single_space_minimal',
10+
],
11+
],
12+
'cast_spaces' => false,
13+
'combine_consecutive_issets' => true,
14+
'function_declaration' => ['closure_function_spacing' => 'none'],
15+
'function_typehint_space' => true,
16+
'hash_to_slash_comment' => true,
17+
'include' => true,
18+
'method_chaining_indentation' => true,
19+
'no_blank_lines_after_class_opening' => true,
20+
'no_closing_tag' => true,
21+
'no_empty_statement' => true,
22+
'no_multiline_whitespace_before_semicolons' => true,
23+
'no_short_echo_tag' => true,
24+
'no_trailing_whitespace' => true,
25+
'no_trailing_whitespace_in_comment' => true,
26+
'no_unneeded_control_parentheses' => ['return'],
27+
'no_useless_return' => true,
28+
'no_whitespace_before_comma_in_array' => true,
29+
'no_whitespace_in_blank_line' => true,
30+
'not_operator_with_successor_space' => false,
31+
'semicolon_after_instruction' => true,
32+
'standardize_not_equals' => true,
33+
'ternary_operator_spaces' => true,
34+
'ternary_to_null_coalescing' => true,
35+
'trim_array_spaces' => true,
36+
'whitespace_after_comma_in_array' => true,
37+
];
38+
$excludes = [
39+
'vendor',
40+
'node_modules',
41+
];
42+
return PhpCsFixer\Config::create()
43+
->setRules($rules)
44+
->setFinder(
45+
PhpCsFixer\Finder::create()
46+
->exclude($excludes)
47+
->notName('*.js')
48+
->notName('*.css')
49+
->notName('*.md')
50+
->notName('*.xml')
51+
->notName('*.yml')
52+
->notName('*.tpl.php')
53+
);

.travis.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

composer.json

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
11
{
2-
"name": "vectorface/snappy-router",
3-
"description": "A quick and snappy routing framework.",
4-
"keywords": [
5-
"MVC", "routing", "router", "drinking bird"
6-
],
7-
"type": "library",
8-
"license": "MIT",
9-
"authors": [
10-
{
11-
"name": "Daniel Bruce",
12-
"email": "[email protected]",
13-
"role": "Developer"
14-
}
15-
],
16-
"autoload": {
17-
"psr-4": {
18-
"Vectorface\\SnappyRouter\\": "./src/Vectorface/SnappyRouter"
19-
},
20-
"files": [
21-
"./src/Vectorface/SnappyRouter/php-5.3-compat.php"
22-
]
23-
},
24-
"autoload-dev": {
25-
"psr-4": {
26-
"Vectorface\\SnappyRouterTests\\": "./tests/Vectorface/SnappyRouterTests"
27-
}
28-
},
29-
"homepage": "https://github.com/Vectorface/snappy-router",
30-
"support": {
31-
"issues": "https://github.com/Vectorface/snappy-router/issues",
32-
"source": "https://github.com/Vectorface/snappy-router"
33-
},
34-
"require": {
35-
"php": ">=5.3.0",
36-
"vectorface/whip": "~0.2",
37-
"twig/twig": "~1.0",
38-
"danbruce/fast-route":"~0.6",
39-
"psr/log": "~1.0"
40-
},
41-
"require-dev": {
42-
"phpunit/phpunit": "^4.8",
43-
"squizlabs/php_codesniffer": "1.*",
44-
"vectorface/dunit": "~2.0"
2+
"name": "vectorface/snappy-router",
3+
"description": "A quick and snappy routing framework.",
4+
"keywords": [
5+
"MVC", "routing", "router", "drinking bird"
6+
],
7+
"type": "library",
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "Daniel Bruce",
12+
"email": "[email protected]",
13+
"role": "Developer"
14+
}
15+
],
16+
"autoload": {
17+
"psr-4": {
18+
"Vectorface\\SnappyRouter\\": "./src/Vectorface/SnappyRouter"
4519
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"Vectorface\\SnappyRouterTests\\": "./tests/Vectorface/SnappyRouterTests"
24+
}
25+
},
26+
"homepage": "https://github.com/Vectorface/snappy-router",
27+
"support": {
28+
"issues": "https://github.com/Vectorface/snappy-router/issues",
29+
"source": "https://github.com/Vectorface/snappy-router"
30+
},
31+
"require": {
32+
"php": ">=7.0.0",
33+
"vectorface/whip": "^0.4",
34+
"twig/twig": "^2.0",
35+
"nikic/fast-route":"^1.0.0",
36+
"psr/log": "^1.0",
37+
"ext-json": "*"
38+
},
39+
"require-dev": {
40+
"phpunit/phpunit": "^4.8",
41+
"squizlabs/php_codesniffer": "1.*",
42+
"vectorface/dunit": "~2.0"
43+
},
44+
"scripts": {
45+
"test": [
46+
"@test-unit"
47+
],
48+
"test-unit": "phpunit --color=always"
49+
}
4650
}

docs/di.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MyDi extends Di
4949
{
5050
public function __construct()
5151
{
52-
parent::__construct(array(
52+
parent::__construct([
5353
...
5454
'database' => function(Di $di) {
5555
return new \PDO(
@@ -59,7 +59,7 @@ class MyDi extends Di
5959
);
6060
},
6161
...
62-
));
62+
]);
6363
}
6464
}
6565
```
@@ -71,12 +71,12 @@ Next specify the DI class in the configuration.
7171

7272
use Vectorface\SnappyRouter\Config\Config;
7373

74-
$config = new Config(array(
74+
$config = new Config([
7575
Config::KEY_DI => 'Vendor\\MyNamespace\\Di\\MyDi',
76-
Config::KEY_HANDLERS => array(
76+
Config::KEY_HANDLERS => [
7777
...
78-
)
79-
));
78+
]
79+
]);
8080
$router = new Vectorface\SnappyRouter\SnappyRouter($config);
8181
echo $router->handleRoute();
8282
```
@@ -86,15 +86,14 @@ echo $router->handleRoute();
8686
SnappyRouter also provides a default DI class that can be configured when your
8787
application bootstraps. For example:
8888

89-
9089
```php
9190
<?php
9291

9392
use Vectorface\SnappyRouter\Config\Config;
9493

95-
$config = new Config(array(
94+
$config = new Config([
9695
...
97-
));
96+
]);
9897
$router = new Vectorface\SnappyRouter\SnappyRouter($config);
9998

10099
// configure the DI manually

docs/getting_started.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Create the file `tutorial/composer.json` with the following contents:
6969
}
7070
},
7171
"require": {
72-
"php": ">=5.3.0",
73-
"vectorface/snappy-router": "dev-master"
72+
"php": ">=7.0.0",
73+
"vectorface/snappy-router": "v0.3.0"
7474
}
7575
}
7676
```
@@ -90,27 +90,28 @@ require_once __DIR__.'/../vendor/autoload.php';
9090

9191
use Vectorface\SnappyRouter\Config\Config;
9292
use Vectorface\SnappyRouter\Handler\ControllerHandler;
93-
94-
$config = new Config(array(
95-
Config::KEY_DI => 'Vectorface\\SnappyTutorial\\Models\\TutorialDi',
96-
Config::KEY_HANDLERS => array(
97-
'PageHandler' => array(
98-
Config::KEY_CLASS => 'Vectorface\\SnappyRouter\\Handler\\ControllerHandler',
99-
Config::KEY_OPTIONS => array(
93+
use Vectorface\SnappyTutorial\Models\TutorialDi;
94+
95+
$config = new Config([
96+
Config::KEY_DI => TutorialDi::class,
97+
Config::KEY_HANDLERS => [
98+
'PageHandler' => [
99+
Config::KEY_CLASS => ControllerHandler::class,
100+
Config::KEY_OPTIONS => [
100101
Config::KEY_NAMESPACES => 'Vectorface\\SnappyTutorial\\Controllers',
101102
ControllerHandler::KEY_BASE_PATH => '/tutorial',
102-
ControllerHandler::KEY_VIEWS => array(
103+
ControllerHandler::KEY_VIEWS => [
103104
ControllerHandler::KEY_VIEWS_PATH => realpath(__DIR__.'/../app/Views')
104-
)
105-
)
106-
)
107-
)
108-
));
105+
]
106+
]
107+
]
108+
]
109+
]);
109110
$router = new Vectorface\SnappyRouter\SnappyRouter($config);
110111
echo $router->handleRoute();
111112
```
112113

113-
For simplicity we include the configuration settings directly in
114+
For simplicity, we include the configuration settings directly in
114115
`public/index.php`. It is probably a better practice to store these settings
115116
in a separate config file and include it in the index. For example:
116117

@@ -134,7 +135,7 @@ the database adapter, cache adapters, mail senders, etc.
134135
For this tutorial, we specify a class to use for DI. Create the file
135136
`app/Models/TutorialDi.php` with the following contents:
136137

137-
```
138+
```php
138139
<?php // app/Models/TutorialDi.php
139140

140141
namespace Vectorface\SnappyTutorial\Models;
@@ -151,11 +152,11 @@ class TutorialDi extends Di
151152

152153
protected function getDiArray()
153154
{
154-
return array(
155+
return [
155156
'projectTitle' => function(Di $di) {
156157
return 'SnappyRouter Tutorial';
157158
}
158-
);
159+
];
159160
}
160161
}
161162
```
@@ -164,7 +165,7 @@ This container registers only the `projectTitle` key.
164165

165166
## Controllers and Views
166167

167-
We will setup an `IndexController` that extends our own abstract controller.
168+
We will set up an `IndexController` that extends our own abstract controller.
168169
It is good practice to always include your own base controller on top of
169170
`Vectorface\SnappyRouter\Controller\AbstractController` to provide common logic
170171
across all your controllers.
@@ -203,9 +204,9 @@ class IndexController extends BaseController
203204
{
204205
public function indexAction()
205206
{
206-
return array(
207+
return [
207208
'content' => 'Hello SnappyRouter!'
208-
);
209+
];
209210
}
210211
}
211212
```

0 commit comments

Comments
 (0)