Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nk-scanner into develop
  • Loading branch information
mirko-pagliai committed Jan 2, 2020
2 parents f746a81 + 32bc66f commit 2e22e2a
Show file tree
Hide file tree
Showing 38 changed files with 192 additions and 117 deletions.
13 changes: 2 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

matrix:
fast_finish: true

include:
- php: 5.6
env: dependencies=lowest
- php: 7.0
env: dependencies=lowest
- php: 7.1
env: dependencies=lowest
- php: 7.2
env: dependencies=lowest
- php: 7.3
env: dependencies=lowest
- php: 7.0
- php: 7.2
env: PHPCS=1
- php: 7.0
- php: 7.2
env: COVERAGE=1

install:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 1.x branch
## 1.1 branch
### 1.1.0
* updated for `cakephp` 4 and `phpunit` 8.

## 1.0 branch
### 1.0.8
* APIs are now generated by `phpDocumentor` and no longer by` apigen`.
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"type": "cakephp-plugin",
"license": "MIT",
"authors": [{
"name": "Mirko Pagliai",
"email": "[email protected]"
}],
"name": "Mirko Pagliai",
"email": "[email protected]"
}],
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "^3.7.1",
"mirko-pagliai/me-tools": "^2.18.9",
"mirko-pagliai/php-tools": "^1.2.6"
"php": ">=7.2",
"cakephp/cakephp": "^4.0",
"mirko-pagliai/me-tools": "^2.19",
"mirko-pagliai/php-tools": "^1.3"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.7.14|^6.0"
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
<file>.</file>

<rule ref="./vendor/mirko-pagliai/php-tools/sniffer-ruleset.xml"/>

<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse">
<exclude-pattern>/tests/test_app/TestApp/Template/Error/error500.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace.UseFromSameNamespace">
<severity>0</severity>
</rule>
</ruleset>
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>

Expand Down
7 changes: 4 additions & 3 deletions src/Command/LinkScannerCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand Down Expand Up @@ -36,7 +37,7 @@ class LinkScannerCommand extends Command
* @return void
* @uses $LinkScanner
*/
public function initialize()
public function initialize(): void
{
$this->LinkScanner = $this->LinkScanner ?: new LinkScanner();
}
Expand All @@ -49,7 +50,7 @@ public function initialize()
* @see LinkScannerCommandEventListener::implementedEvents()
* @uses $LinkScanner
*/
public function execute(Arguments $args, ConsoleIo $io)
public function execute(Arguments $args, ConsoleIo $io): ?int
{
try {
//Will trigger events provided by `LinkScannerCommandEventListener`
Expand Down Expand Up @@ -96,7 +97,7 @@ public function execute(Arguments $args, ConsoleIo $io)
* @return \Cake\Console\ConsoleOptionParser The built parser
* @uses $LinkScanner
*/
protected function buildOptionParser(ConsoleOptionParser $parser)
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser->setDescription(__d('link-scanner', 'Performs a complete scan'));

Expand Down
26 changes: 14 additions & 12 deletions src/Event/LinkScannerCommandEventListener.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand Down Expand Up @@ -59,7 +60,7 @@ public function __construct(Arguments $args, ConsoleIo $io)
* associated with the respective event
* @return array
*/
public function implementedEvents()
public function implementedEvents(): array
{
$events = [
'afterScanUrl',
Expand All @@ -71,7 +72,7 @@ public function implementedEvents()
'scanStarted',
];

return array_combine(array_map(function ($event) {
return array_combine(array_map(function (string $event) {
return 'LinkScanner.' . $event;
}, $events), $events);
}
Expand All @@ -84,7 +85,7 @@ public function implementedEvents()
* @uses $args
* @uses $io
*/
public function afterScanUrl(Event $event, Response $response)
public function afterScanUrl(Event $event, Response $response): bool
{
if (!$this->args->getOption('verbose')) {
return true;
Expand All @@ -104,7 +105,7 @@ public function afterScanUrl(Event $event, Response $response)
* @return bool
* @uses $io
*/
public function beforeScanUrl(Event $event, $url)
public function beforeScanUrl(Event $event, string $url): bool
{
$this->io->verbose(__d('link-scanner', 'Checking {0} ...', $url), 0);

Expand All @@ -118,7 +119,7 @@ public function beforeScanUrl(Event $event, $url)
* @return bool
* @uses $io
*/
public function foundLinkToBeScanned(Event $event, $link)
public function foundLinkToBeScanned(Event $event, string $link): bool
{
$this->io->verbose(__d('link-scanner', 'Link found: {0}', $link));

Expand All @@ -132,7 +133,7 @@ public function foundLinkToBeScanned(Event $event, $link)
* @return bool
* @uses $io
*/
public function foundRedirect(Event $event, $url)
public function foundRedirect(Event $event, string $url): bool
{
$this->io->verbose(__d('link-scanner', 'Redirect found: {0}', $url));

Expand All @@ -146,7 +147,7 @@ public function foundRedirect(Event $event, $url)
* @return bool
* @uses $io
*/
public function resultsExported(Event $event, $filename)
public function resultsExported(Event $event, string $filename): bool
{
$this->io->success(__d('link-scanner', 'Results have been exported to {0}', $filename));

Expand All @@ -157,10 +158,11 @@ public function resultsExported(Event $event, $filename)
* `LinkScanner.resultsImported` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $filename Filename
* @return void
* @return bool
*/
public function resultsImported(Event $event, $filename)
public function resultsImported(Event $event, string $filename): bool
{
return true;
}

/**
Expand All @@ -173,7 +175,7 @@ public function resultsImported(Event $event, $filename)
* @uses $args
* @uses $io
*/
public function scanCompleted(Event $event, $startTime, $endTime, ResultScan $ResultScan)
public function scanCompleted(Event $event, int $startTime, int $endTime, ResultScan $ResultScan): bool
{
if ($this->args->getOption('verbose')) {
$this->io->hr();
Expand Down Expand Up @@ -202,7 +204,7 @@ public function scanCompleted(Event $event, $startTime, $endTime, ResultScan $Re
* @uses $args
* @uses $io
*/
public function scanStarted(Event $event, $startTime, $fullBaseUrl)
public function scanStarted(Event $event, int $startTime, string $fullBaseUrl): bool
{
if ($this->args->getOption('verbose')) {
$this->io->hr();
Expand All @@ -218,7 +220,7 @@ public function scanStarted(Event $event, $startTime, $fullBaseUrl)
$this->io->hr();

$cache = Cache::getConfig('LinkScanner');
list($method, $message) = ['info', __d('link-scanner', 'The cache is disabled')];
[$method, $message] = ['info', __d('link-scanner', 'The cache is disabled')];
if (!$this->args->getOption('no-cache') && Cache::enabled() && !empty($cache['duration'])) {
$method = 'success';
$message = __d('link-scanner', 'The cache is enabled and its duration is `{0}`', $cache['duration']);
Expand Down
17 changes: 9 additions & 8 deletions src/Event/LinkScannerEventListenerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand Down Expand Up @@ -28,47 +29,47 @@ interface LinkScannerEventListenerInterface extends EventListenerInterface
* @param \Cake\Http\Client\Response $response A `Response` instance
* @return bool
*/
public function afterScanUrl(Event $event, Response $response);
public function afterScanUrl(Event $event, Response $response): bool;

/**
* `LinkScanner.beforeScanUrl` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $url Url
* @return bool
*/
public function beforeScanUrl(Event $event, $url);
public function beforeScanUrl(Event $event, string $url): bool;

/**
* `LinkScanner.foundLinkToBeScanned` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $link Link
* @return bool
*/
public function foundLinkToBeScanned(Event $event, $link);
public function foundLinkToBeScanned(Event $event, string $link): bool;

/**
* `LinkScanner.foundRedirect` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $redirect Redirect
* @return bool
*/
public function foundRedirect(Event $event, $redirect);
public function foundRedirect(Event $event, string $redirect): bool;

/**
* `LinkScanner.resultsExported` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $filename Filename
* @return bool
*/
public function resultsExported(Event $event, $filename);
public function resultsExported(Event $event, string $filename): bool;

/**
* `LinkScanner.resultsImported` event
* @param \Cake\Event\Event $event An `Event` instance
* @param string $filename Filename
* @return bool
*/
public function resultsImported(Event $event, $filename);
public function resultsImported(Event $event, string $filename): bool;

/**
* `LinkScanner.scanCompleted` event
Expand All @@ -78,7 +79,7 @@ public function resultsImported(Event $event, $filename);
* @param \LinkScanner\ResultScan $ResultScan A `ResultScan` instance
* @return bool
*/
public function scanCompleted(Event $event, $startTime, $endTime, ResultScan $ResultScan);
public function scanCompleted(Event $event, int $startTime, int $endTime, ResultScan $ResultScan): bool;

/**
* `LinkScanner.scanStarted` event
Expand All @@ -87,5 +88,5 @@ public function scanCompleted(Event $event, $startTime, $endTime, ResultScan $Re
* @param string $fullBaseUrl Full base url
* @return bool
*/
public function scanStarted(Event $event, $startTime, $fullBaseUrl);
public function scanStarted(Event $event, int $startTime, string $fullBaseUrl): bool;
}
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand Down
18 changes: 10 additions & 8 deletions src/ResultScan.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand All @@ -13,6 +14,7 @@
namespace LinkScanner;

use Cake\Collection\Collection;
use Cake\Collection\CollectionInterface;
use LinkScanner\ScanEntity;
use Traversable;

Expand All @@ -25,10 +27,10 @@ class ResultScan extends Collection
* Internal method to parse items.
*
* Ensures that each item is a `ScanEntity` and has all the properties it needs
* @param array|\Traversable $items Array of items
* @param iterable $items Items
* @return array Parsed items
*/
protected function parseItems($items)
protected function parseItems(iterable $items): array
{
$items = $items instanceof Traversable ? $items->toArray() : $items;

Expand All @@ -39,10 +41,10 @@ protected function parseItems($items)

/**
* Constructor
* @param array|\Traversable $items Items
* @param iterable $items Items
* @uses parseItems()
*/
public function __construct($items = [])
public function __construct(iterable $items = [])
{
parent::__construct($this->parseItems($items));
}
Expand All @@ -52,11 +54,11 @@ public function __construct($items = [])
*
* Returns a new `ResultScan` instance as the result of concatenating the
* list of elements in this collection with the passed list of elements
* @param array|\Traversable $items Items
* @param iterable $items Items
* @return \Cake\Collection\CollectionInterface
* @uses parseItems()
*/
public function append($items)
public function append($items): CollectionInterface
{
return new ResultScan(array_merge($this->buffered()->toArray(), $this->parseItems($items)));
}
Expand All @@ -66,11 +68,11 @@ public function append($items)
*
* Returns a new `ResultScan` instance as the result of concatenating the
* passed list of elements with the list of elements in this collection
* @param array|\Traversable $items Items
* @param iterable $items Items
* @return \Cake\Collection\CollectionInterface
* @uses parseItems()
*/
public function prepend($items)
public function prepend($items): CollectionInterface
{
return new ResultScan(array_merge($this->parseItems($items), $this->buffered()->toArray()));
}
Expand Down
3 changes: 2 additions & 1 deletion src/ScanEntity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* This file is part of cakephp-link-scanner.
*
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(array $properties = [])
* @return mixed
* @see \Cake\Http\Client\Response
*/
public function __call($name, $arguments)
public function __call(string $name, $arguments)
{
if (method_exists(Response::class, $name)) {
$response = (new Response())
Expand Down
Loading

0 comments on commit 2e22e2a

Please sign in to comment.