Skip to content

Commit a28464f

Browse files
authored
Merge pull request #41 from niden/master
v5.0.0 prep
2 parents 4d46e94 + 3272093 commit a28464f

File tree

160 files changed

+6198
-4158
lines changed

Some content is hidden

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

160 files changed

+6198
-4158
lines changed

.github/workflows/main.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Testing Suite
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
DATA_API_MYSQL_HOST: '127.0.0.1'
7+
DATA_API_REDIS_HOST: '127.0.0.1'
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
name: Workflow - PHP-${{ matrix.php }}
13+
14+
services:
15+
mysql:
16+
image: mysql:5.7
17+
ports:
18+
- "3306:3306"
19+
env:
20+
MYSQL_ROOT_PASSWORD: secret
21+
MYSQL_USER: phalcon
22+
MYSQL_DATABASE: phalcon_api
23+
MYSQL_PASSWORD: secret
24+
redis:
25+
image: redis:5-alpine
26+
ports:
27+
- "6379:6379"
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
php: ['8.0', '8.1' ]
33+
34+
steps:
35+
- uses: actions/checkout@v1
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
tools: pecl
41+
extensions: mbstring, intl, json, phalcon-5.0.0RC4
42+
coverage: xdebug
43+
44+
- name: Init Database
45+
run: |
46+
mysql -uroot -h127.0.0.1 -psecret -e 'CREATE DATABASE IF NOT EXISTS `phalcon_api`;'
47+
48+
- name: Validate composer.json and composer.lock
49+
run: composer validate
50+
51+
- name: Get composer cache directory
52+
id: composer-cache
53+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
54+
55+
- name: Cache dependencies
56+
uses: actions/cache@v2
57+
with:
58+
path: ${{ steps.composer-cache.outputs.dir }}
59+
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
60+
restore-keys: ${{ matrix.php }}-composer-
61+
62+
- name: Install Composer dependencies
63+
run: composer install --prefer-dist --no-progress --no-suggest
64+
65+
- name: Run PHPCS
66+
if: always()
67+
run: vendor/bin/phpcs
68+
69+
- name: Env file
70+
if: always()
71+
run: cp -v ./storage/config/.env.ci ./.env
72+
73+
- name: Run migrations
74+
if: always()
75+
run: |
76+
vendor/bin/phinx migrate
77+
78+
- name: Run tests
79+
if: always()
80+
run: |
81+
sudo php -S 0.0.0.0 -t ./.htrouter.php &
82+
vendor/bin/codecept build
83+
vendor/bin/codecept run unit --coverage-xml=unit-coverage.xml
84+
vendor/bin/codecept run integration --coverage-xml=integration-coverage.xml
85+
vendor/bin/codecept run cli --coverage-xml=cli-coverage.xml
86+
# vendor/bin/codecept run api --coverage-xml=api-coverage.xml
87+
88+
- name: Upload to codecov
89+
uses: codecov/codecov-action@v3
90+
with:
91+
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
92+
directory: ./tests/_output/
93+
files: unit-coverage.xml,integration-coverage.xml,cli-coverage.xml
94+
name: codecov-umbrella # optional
95+
fail_ci_if_error: false
96+
verbose: true # optional (default = false)

.github/workflows/php.yml

-39
This file was deleted.

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
# https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
77

88
.env
9-
phinx.php
109
tests/_output/
1110
vendor/

.htrouter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
$_GET['_url'] = $_SERVER['REQUEST_URI'];
1212

13-
require_once __DIR__ . '/public/index.php';
13+
require_once __DIR__ . '/api/public/index.php';

.nanoignore

-5
This file was deleted.

api/config/providers.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
declare(strict_types=1);
32

43
/**
54
* This file is part of the Phalcon API.
@@ -10,6 +9,8 @@
109
* the LICENSE file that was distributed with this source code.
1110
*/
1211

12+
declare(strict_types=1);
13+
1314
use Phalcon\Api\Providers\CacheDataProvider;
1415
use Phalcon\Api\Providers\ConfigProvider;
1516
use Phalcon\Api\Providers\DatabaseProvider;

api/controllers/BaseController.php

+42-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
declare(strict_types=1);
32

43
/**
54
* This file is part of the Phalcon API.
@@ -10,21 +9,26 @@
109
* the LICENSE file that was distributed with this source code.
1110
*/
1211

12+
declare(strict_types=1);
13+
1314
namespace Phalcon\Api\Api\Controllers;
1415

1516
use Phalcon\Api\Http\Response;
1617
use Phalcon\Api\Traits\FractalTrait;
1718
use Phalcon\Api\Traits\QueryTrait;
1819
use Phalcon\Api\Traits\ResponseTrait;
19-
use Phalcon\Cache;
20-
use Phalcon\Config;
21-
use Phalcon\Filter;
20+
use Phalcon\Cache\Cache;
21+
use Phalcon\Config\Config;
22+
use Phalcon\Filter\Exception;
23+
use Phalcon\Filter\Filter;
2224
use Phalcon\Mvc\Controller;
2325
use Phalcon\Mvc\Micro;
2426
use Phalcon\Mvc\Model\MetaData\Libmemcached as ModelsMetadataCache;
27+
2528
use function explode;
2629
use function implode;
2730
use function in_array;
31+
use function str_starts_with;
2832
use function strtolower;
2933
use function substr;
3034

@@ -44,32 +48,35 @@ class BaseController extends Controller
4448
use ResponseTrait;
4549

4650
/** @var string */
47-
protected $model = '';
51+
protected string $model = '';
4852

4953
/** @var array */
50-
protected $includes = [];
54+
protected array $includes = [];
5155

5256
/** @var string */
53-
protected $method = 'collection';
57+
protected string $method = 'collection';
5458

5559
/** @var string */
56-
protected $orderBy = 'name';
60+
protected string $orderBy = 'name';
5761

5862
/** @var string */
59-
protected $resource = '';
63+
protected string $resource = '';
6064

6165
/** @var array */
62-
protected $sortFields = [];
66+
protected array $sortFields = [];
6367

6468
/** @var string */
65-
protected $transformer = '';
69+
protected string $transformer = '';
6670

6771
/**
6872
* Get the company/companies
6973
*
70-
* @param int $id
74+
* @param mixed $id
75+
*
76+
* @return void
77+
* @throws Exception
7178
*/
72-
public function callAction($id = 0)
79+
public function callAction(mixed $id = 0): void
7380
{
7481
$parameters = $this->checkIdParameter($id);
7582
$fields = $this->checkFields();
@@ -79,7 +86,14 @@ public function callAction($id = 0)
7986
if (true !== $validSort) {
8087
$this->sendError($this->response::BAD_REQUEST);
8188
} else {
82-
$results = $this->getRecords($this->config, $this->cache, $this->model, $parameters, $this->orderBy);
89+
$results = $this->getRecords(
90+
$this->config,
91+
$this->cache,
92+
$this->model,
93+
$parameters,
94+
$this->orderBy
95+
);
96+
8397
if (count($parameters) > 0 && 0 === count($results)) {
8498
$this->sendError($this->response::NOT_FOUND);
8599
} else {
@@ -93,15 +107,23 @@ public function callAction($id = 0)
93107
);
94108
$this
95109
->response
96-
->setPayloadSuccess($data);
110+
->setPayloadSuccess($data)
111+
;
97112
}
98113
}
99114
}
100115

116+
/**
117+
* @return array
118+
*/
101119
private function checkFields(): array
102120
{
103121
$data = [];
104-
$fieldSent = $this->request->getQuery('fields', [Filter::FILTER_STRING, Filter::FILTER_TRIM], []);
122+
$fieldSent = $this->request->getQuery(
123+
'fields',
124+
[Filter::FILTER_STRING, Filter::FILTER_TRIM],
125+
[]
126+
);
105127
foreach ($fieldSent as $resource => $fields) {
106128
$data[$resource] = explode(',', $fields);
107129
}
@@ -112,11 +134,12 @@ private function checkFields(): array
112134
/**
113135
* Checks the passed id parameter and returns the relevant array back
114136
*
115-
* @param int $recordId
137+
* @param mixed $recordId
116138
*
117139
* @return array
140+
* @throws Exception
118141
*/
119-
private function checkIdParameter($recordId = 0): array
142+
private function checkIdParameter(mixed $recordId = 0): array
120143
{
121144
$parameters = [];
122145

@@ -202,7 +225,7 @@ private function getFieldAndDirection(string $field): array
202225
/**
203226
* Ascending or descending
204227
*/
205-
if ('-' === substr($trueField, 0, 1)) {
228+
if (true === str_starts_with($trueField, '-')) {
206229
$trueField = substr($trueField, 1);
207230
$direction = ' desc';
208231
}

api/controllers/Companies/AddController.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
declare(strict_types=1);
32

43
/**
54
* This file is part of the Phalcon API.
@@ -10,6 +9,8 @@
109
* the LICENSE file that was distributed with this source code.
1110
*/
1211

12+
declare(strict_types=1);
13+
1314
namespace Phalcon\Api\Api\Controllers\Companies;
1415

1516
use Phalcon\Api\Constants\Relationships;
@@ -19,8 +20,9 @@
1920
use Phalcon\Api\Traits\FractalTrait;
2021
use Phalcon\Api\Transformers\BaseTransformer;
2122
use Phalcon\Api\Validation\CompaniesValidator;
22-
use Phalcon\Filter;
23+
use Phalcon\Filter\Filter;
2324
use Phalcon\Mvc\Controller;
25+
2426
use function Phalcon\Api\Core\appUrl;
2527

2628
/**
@@ -57,10 +59,17 @@ public function callAction()
5759
->set('address', $address)
5860
->set('city', $city)
5961
->set('phone', $phone)
60-
->save();
62+
->save()
63+
;
6164

6265
if (false !== $result) {
63-
$data = $this->format('item', $company, BaseTransformer::class, 'companies');
66+
$data = $this->format(
67+
'item',
68+
$company,
69+
BaseTransformer::class,
70+
'companies'
71+
);
72+
6473
$this
6574
->response
6675
->setHeader('Location', appUrl(Relationships::COMPANIES, $company->get('id')))
@@ -73,15 +82,17 @@ public function callAction()
7382
*/
7483
$this
7584
->response
76-
->setPayloadErrors($company->getMessages());
85+
->setPayloadErrors($company->getMessages())
86+
;
7787
}
7888
} else {
7989
/**
8090
* Set the errors in the payload
8191
*/
8292
$this
8393
->response
84-
->setPayloadErrors($messages);
94+
->setPayloadErrors($messages)
95+
;
8596
}
8697
}
8798
}

0 commit comments

Comments
 (0)