Skip to content

Commit

Permalink
Merge pull request #23 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Jan 2, 2020
2 parents d92870d + 2e22e2a commit b547c1d
Show file tree
Hide file tree
Showing 39 changed files with 209 additions and 125 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
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://api.travis-ci.org/mirko-pagliai/cakephp-link-scanner.svg?branch=master)](https://travis-ci.org/mirko-pagliai/cakephp-link-scanner)
[![Build status](https://ci.appveyor.com/api/projects/status/hqk7fxtad6r75wk3?svg=true)](https://ci.appveyor.com/project/mirko-pagliai/cakephp-link-scanner)
[![codecov](https://codecov.io/gh/mirko-pagliai/cakephp-link-scanner/branch/master/graph/badge.svg)](https://codecov.io/gh/mirko-pagliai/cakephp-link-scanner)
[![CodeFactor](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-link-scanner/badge/cakephp4)](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-link-scanner/overview/cakephp4)
[![CodeFactor](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-link-scanner/badge)](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-link-scanner)

*LinkScanner* is a CakePHP plugin for recursively scanning links: starting from
a full base url, it performs GET requests, checks the status codes, inspects the
Expand All @@ -13,7 +13,7 @@ response bodies and, if it finds other links, it continues recursively scanning.
![gif of terminal](https://github.com/mirko-pagliai/cakephp-link-scanner/raw/master/docs/tty.gif)

Did you like this plugin? Its development requires a lot of time for me.
Please consider the possibility of making [a donation](//paypal.me/mirkopagliai):
Please consider the possibility of making [a donation](//paypal.me/mirkopagliai):
even a coffee is enough! Thank you.

[![Make a donation](https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_carte.jpg)](//paypal.me/mirkopagliai)
Expand All @@ -24,10 +24,19 @@ You can install the plugin via composer:
$ composer require --prefer-dist mirko-pagliai/cakephp-link-scanner
```

**NOTE: the latest version available requires at least CakePHP 3.7.1**.

**NOTE: the latest version available requires at least CakePHP 4**.

Instead, the [cakephp3](//github.com/mirko-pagliai/cakephp-link-scanner/tree/cakephp3)
branch is compatible with all previous versions of CakePHP from version 3.7.1.
This branch coincides with the current version of *cakephp-link-scanner*.

In this case, you can install the package as well:

```bash
$ composer require --prefer-dist mirko-pagliai/cakephp-link-scanner:dev-cakephp3

Then you have to load the plugin. For more information on how to load the plugin,
please refer to the [Cookbook](//book.cakephp.org/3.0/en/plugins.html#loading-a-plugin).
please refer to the [Cookbook](//book.cakephp.org/4.0/en/plugins.html#loading-a-plugin).

Simply, you can execute the shell command to enable the plugin:
```bash
Expand All @@ -37,7 +46,7 @@ This would update your application's bootstrap method.
## Configuration
It's not essential, but it may be useful to set the `App.fullBaseUrl` value
correctly [refer to the Cookbook](//book.cakephp.org/3.0/en/development/configuration.html#general-configuration),
correctly [refer to the Cookbook](//book.cakephp.org/4.0/en/development/configuration.html#general-configuration),
especially if you plan to use the plugin mainly on your app, so as not to have
to indicate the full base url which to start the scan every time.

Expand All @@ -54,6 +63,6 @@ In addition, you can refer to our [API](//mirko-pagliai.github.io/cakephp-link-s
* allow to export results as html and/or xml.

## Versioning
For transparency and insight into our release cycle and to maintain backward
compatibility, *Assets* will be maintained under the
For transparency and insight into our release cycle and to maintain backward
compatibility, *Assets* will be maintained under the
[Semantic Versioning guidelines](//semver.org).
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
Loading

0 comments on commit b547c1d

Please sign in to comment.