Skip to content

Commit

Permalink
Merge pull request #49 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
many, small improvements proposed by phpstorm
  • Loading branch information
mirko-pagliai authored Mar 24, 2023
2 parents db1bf6e + 6c7ec4d commit 78524da
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 1.x branch
## 1.1 branch
### 1.1.16
* added the `LINK_SCANNER_TMP` constant. This constant, which can be defined before the plugin, affects all used files;
* many, small improvements proposed by phpstorm.

### 1.1.15
* the `LinkScannerCommand` also prints the total number of invalid links to the console;
* many, small code tweaks proposed by phpstorm;
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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):
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)
[![Make a donation](https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_carte.jpg)](https://paypal.me/mirkopagliai)

***

Expand All @@ -36,7 +36,7 @@ $ composer require --prefer-dist mirko-pagliai/cakephp-link-scanner
```

Then you have to load the plugin. For more information on how to load the plugin,
please refer to the [Cookbook](//book.cakephp.org/4.0/en/plugins.html#loading-a-plugin).
please refer to the [Cookbook](https://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 @@ -52,7 +52,7 @@ However, there are still some branches compatible with previous versions of
CakePHP and PHP.

#### For PHP 7.2 or later
The [php7.2](//github.com/mirko-pagliai/cakephp-link-scanner/tree/php7.2) branch
The [php7.2](https://github.com/mirko-pagliai/cakephp-link-scanner/tree/php7.2) branch
requires at least PHP 7.2.

In this case, you can install the package as well:
Expand All @@ -79,17 +79,17 @@ except for security patches, and it matches the

## Configuration
It's not essential, but it may be useful to set the `App.fullBaseUrl` value
correctly [refer to the Cookbook](//book.cakephp.org/4.0/en/development/configuration.html#general-configuration),
correctly [refer to the Cookbook](https://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.

## How to use
Please, refer to the wiki:
* [How to use the LinkScanner utility](//github.com/mirko-pagliai/cakephp-link-scanner/wiki/How-to-use-the-LinkScanner-utility)
* [How to use the LinkScannerCommand](//github.com/mirko-pagliai/cakephp-link-scanner/wiki/How-to-use-the-LinkScannerCommand)
* [Examples for ResultScan](//github.com/mirko-pagliai/cakephp-link-scanner/wiki/Examples-for-ResultScan)
* [How to use the LinkScanner utility](https://github.com/mirko-pagliai/cakephp-link-scanner/wiki/How-to-use-the-LinkScanner-utility)
* [How to use the LinkScannerCommand](https://github.com/mirko-pagliai/cakephp-link-scanner/wiki/How-to-use-the-LinkScannerCommand)
* [Examples for ResultScan](https://github.com/mirko-pagliai/cakephp-link-scanner/wiki/Examples-for-ResultScan)

In addition, you can refer to our [API](//mirko-pagliai.github.io/cakephp-link-scanner).
In addition, you can refer to our [API](https://mirko-pagliai.github.io/cakephp-link-scanner).

## To do list
* allow the use of a configuration file for the shell;
Expand All @@ -98,4 +98,4 @@ In addition, you can refer to our [API](//mirko-pagliai.github.io/cakephp-link-s
## Versioning
For transparency and insight into our release cycle and to maintain backward
compatibility, *Assets* will be maintained under the
[Semantic Versioning guidelines](//semver.org).
[Semantic Versioning guidelines](https://semver.org).
7 changes: 6 additions & 1 deletion config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@

use Cake\Cache\Cache;

//Default LinkScanner tmp
if (!defined('LINK_SCANNER_TMP')) {
define('LINK_SCANNER_TMP', TMP . 'cakephp-link-scanner' . DS);
}

if (!Cache::getConfig('LinkScanner')) {
Cache::setConfig('LinkScanner', [
'className' => 'File',
'duration' => '+1 day',
'path' => CACHE,
'path' => LINK_SCANNER_TMP . 'cache' . DS,
'prefix' => 'link_scanner_',
]);
}
9 changes: 9 additions & 0 deletions psalm-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<file src="src/Command/LinkScannerCommand.php">
<RedundantPropertyInitializationCheck occurrences="2">
<code>$this-&gt;LinkScanner</code>
<code>new LinkScanner()</code>
</RedundantPropertyInitializationCheck>
</file>
</files>
5 changes: 1 addition & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="tests/bootstrap.php"
errorBaseline="psalm-baseline.neon"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<RedundantPropertyInitializationCheck errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/TestSuite/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function tearDown(): void
{
parent::tearDown();

@unlink(TMP . 'cakephp-link-scanner' . DS . 'link_scanner_lock_file');
@unlink(LINK_SCANNER_TMP . 'link_scanner_lock_file');

Cache::clear('LinkScanner');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/LinkScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LinkScanner implements Serializable
'fullBaseUrl' => null,
'maxDepth' => 0,
'lockFile' => true,
'target' => TMP . 'cakephp-link-scanner',
'target' => LINK_SCANNER_TMP,
];

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ class LinkScanner implements Serializable
* Lock file path
* @var string
*/
protected string $lockFile = TMP . 'cakephp-link-scanner' . DS . 'link_scanner_lock_file';
protected string $lockFile = LINK_SCANNER_TMP . 'link_scanner_lock_file';

/**
* Start time
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Command/LinkScannerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testExecuteParams(): void
$this->Command->run($params, $this->_io);

$expectedDuration = Cache::getConfig('LinkScanner')['duration'];
$expectedFilename = $this->LinkScanner->getConfig('target') . DS . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;
$expectedFilename = $this->LinkScanner->getConfig('target') . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;

$this->assertEquals($expectedConfig, $this->LinkScanner->getConfig());
$this->assertEquals(15, $this->LinkScanner->Client->getConfig('timeout'));
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testExecuteParams(): void
//It also works without the `--export` parameter
self::setUp();
$this->Command->run(array_merge(['--export-only-bad-results'] + $params), $this->_io);
$expectedFilename = $this->LinkScanner->getConfig('target') . DS . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;
$expectedFilename = $this->LinkScanner->getConfig('target') . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;
$this->assertEquals(['exportOnlyBadResults' => true] + $expectedConfig, $this->LinkScanner->getConfig());
$this->assertOutputRegExp(sprintf('/Scan started for %s/', preg_quote($this->LinkScanner->getConfig('fullBaseUrl'), '/')));
$this->assertOutputRegExp('/Total scanned links\: [1-9]\d*/');
Expand Down Expand Up @@ -232,7 +232,7 @@ public function testExecuteParams(): void
$this->assertNotEmpty(array_filter($this->_out->messages(), $differentLines));

foreach ([
'example' => $this->LinkScanner->getConfig('target') . DS . 'example',
'example' => $this->LinkScanner->getConfig('target') . 'example',
TMP . 'example' => TMP . 'example',
] as $filename => $expectedExportFile) {
self::setUp();
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Utility/LinkScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public function testExport(): void

//Filename can be `null`, relative or absolute
foreach ([
null => $target . DS . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime,
'example' => $target . DS . 'example',
null => $target . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime,
'example' => $target . 'example',
TMP . 'example' => TMP . 'example',
] as $filename => $expectedFilename) {
$result = $this->LinkScanner->export($filename);
Expand Down
12 changes: 6 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

define('ROOT', dirname(__DIR__) . DS);
define('VENDOR', ROOT . 'vendor' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp');
define('CORE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS);
define('CAKE', CORE_PATH . 'src' . DS);
define('TESTS', ROOT . 'tests' . DS);
Expand All @@ -32,18 +31,19 @@
define('APP_DIR', 'TestApp');
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', APP . 'webroot' . DS);
define('TMP', sys_get_temp_dir() . DS . 'cakephp-link-scanner-tmp' . DS);
define('TMP', sys_get_temp_dir() . DS);
define('CACHE', TMP . 'cache' . DS);
define('CONFIG', APP . 'config' . DS);
define('LOGS', TMP . 'logs' . DS);
define('SESSIONS', TMP . 'sessions' . DS);

foreach ([TMP, LOGS, SESSIONS, CACHE,CACHE . 'views', CACHE . 'models'] as $dir) {
mkdir($dir);
}

require dirname(__DIR__) . '/vendor/autoload.php';
require CORE_PATH . 'config' . DS . 'bootstrap.php';
require ROOT . 'config' . DS . 'bootstrap.php';

foreach (array_filter([LINK_SCANNER_TMP, LOGS, SESSIONS, CACHE . 'views', CACHE . 'models'], fn(string $dir): bool => !file_exists($dir)) as $dir) {
mkdir($dir, 0777, true);
}

Configure::write('debug', true);
Configure::write('App', [
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.15
1.1.16

0 comments on commit 78524da

Please sign in to comment.