diff --git a/CHANGELOG.md b/CHANGELOG.md index b3beac2..0caa956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ Changelog ========= * 3.0.0 - * CakePHP 5.0 compatible release + * CakePHP 5.1 compatible release * 2.0.0 * CakePHP 4.0 compatible release diff --git a/LICENSE.txt b/LICENSE.txt index 4c66a34..074c57b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License -Copyright 2013-2023 +Copyright 2013-2026 Cake Development Corporation 1785 E. Sahara Avenue, Suite 490-423 Las Vegas, Nevada 89104 diff --git a/README.md b/README.md index 4ea58c0..e1df233 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ CakeDC\Clamav for CakePHP =================== -[![Build Status](https://secure.travis-ci.org/cakedc/cakephp-clamav.png?branch=master)](http://travis-ci.org/cakedc/cakephp-clamav) -[![Coverage Status](https://img.shields.io/codecov/c/gh/cakedc/cakephp-clamav.svg?style=flat-square)](https://codecov.io/gh/cakedc/cakephp-clamav) [![Downloads](https://poser.pugx.org/cakedc/cakephp-clamav/d/total.png)](https://packagist.org/packages/cakedc/cakephp-clamav) [![Latest Version](https://poser.pugx.org/cakedc/cakephp-clamav/v/stable.png)](https://packagist.org/packages/cakedc/cakephp-clamav) [![License](https://poser.pugx.org/cakedc/cakephp-clamav/license.svg)](https://packagist.org/packages/cakedc/cakephp-clamav) @@ -12,8 +10,8 @@ ClamAV integration with CakePHP via Validator Requirements ------------ -* CakePHP 5.0+ -* PHP 8.1+ +* CakePHP 5.1+ +* PHP 8.2+ * Clamd (daemon) up and running, connection via socket Setup @@ -80,7 +78,7 @@ bug fixes to the plugin, please read our [Contribution Guidelines](https://www.c License ------- -Copyright 2013-2023 Cake Development Corporation (CakeDC). All rights reserved. +Copyright 2013-2026 Cake Development Corporation (CakeDC). All rights reserved. Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file. diff --git a/composer.json b/composer.json index 28329aa..24e8d77 100644 --- a/composer.json +++ b/composer.json @@ -4,12 +4,12 @@ "type": "cakephp-plugin", "license": "MIT", "require": { - "php": ">=8.1", - "cakephp/cakephp": "^5.0" + "php": ">=8.2", + "cakephp/cakephp": "^5.1" }, "require-dev": { - "phpunit/phpunit": "^10.0", - "cakephp/cakephp-codesniffer": "^4.0" + "phpunit/phpunit": "^10.1.0", + "cakephp/cakephp-codesniffer": "^5.0" }, "autoload": { "psr-4": { diff --git a/config/bootstrap.php b/config/bootstrap.php index 3dde077..3c8b107 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -2,12 +2,12 @@ declare(strict_types=1); /** - * Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * @copyright Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ use Cake\Core\Configure; diff --git a/phpcs.xml b/phpcs.xml index 71f6bdc..4444446 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,4 @@ - - diff --git a/src/Network/Socket.php b/src/Network/Socket.php deleted file mode 100644 index 4b37c98..0000000 --- a/src/Network/Socket.php +++ /dev/null @@ -1,93 +0,0 @@ -connection) { - $this->disconnect(); - } - - $hasProtocol = str_contains($this->_config['host'], '://'); - if ($hasProtocol) { - [$this->_config['protocol'], $this->_config['host']] = explode('://', $this->_config['host']); - } - $scheme = null; - if (!empty($this->_config['protocol'])) { - $scheme = $this->_config['protocol'] . '://'; - } - - $this->_setSslContext($this->_config['host']); - if (!empty($this->_config['context'])) { - $context = stream_context_create($this->_config['context']); - } else { - $context = stream_context_create(); - } - - $connectAs = STREAM_CLIENT_CONNECT; - if ($this->_config['persistent']) { - $connectAs |= STREAM_CLIENT_PERSISTENT; - } - - set_error_handler([$this, '_connectionErrorHandler']); - $remoteSocketTarget = $scheme . $this->_config['host']; - if ($this->_config['port'] !== null) { - $remoteSocketTarget .= ':' . $this->_config['port']; - } - $errNum = 0; - $errStr = ''; - $this->connection = $this->_getStreamSocketClient( - $remoteSocketTarget, - $errNum, - $errStr, - $this->_config['timeout'], - $connectAs, - $context - ); - restore_error_handler(); - - if (!empty($errNum) || !empty($errStr)) { - $this->setLastError($errNum, $errStr); - throw new SocketException($errStr, $errNum); - } - - if (!$this->connection && $this->_connectionErrors) { - $message = implode("\n", $this->_connectionErrors); - throw new SocketException($message, E_WARNING); - } - - $this->connected = is_resource($this->connection); - if ($this->connected) { - assert($this->connection !== null); - - stream_set_timeout($this->connection, (int)$this->_config['timeout']); - } - - return $this->connected; - } -} diff --git a/src/Validation/ClamdValidation.php b/src/Validation/ClamdValidation.php index 4c23c2b..d9c165e 100644 --- a/src/Validation/ClamdValidation.php +++ b/src/Validation/ClamdValidation.php @@ -2,22 +2,22 @@ declare(strict_types=1); /** - * Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * @copyright Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ namespace CakeDC\Clamav\Validation; use Cake\Core\Configure; use Cake\Log\Log; -use Cake\Network\Socket as BaseSocket; +use Cake\Network\Socket; use Cake\Validation\Validator; -use CakeDC\Clamav\Network\Socket; use Exception; +use OutOfBoundsException; use function Cake\I18n\__d; /** @@ -40,7 +40,7 @@ class ClamdValidation extends Validator * Use clamd socket to scan the uploaded tmp file * * @param mixed $check value to check - * @return bool|string + * @return string|bool */ public function fileHasNoVirusesFound(mixed $check): bool|string { @@ -63,7 +63,7 @@ public function fileHasNoVirusesFound(mixed $check): bool|string '{0} while checking the file {1} for viruses: {2}', get_class($ex), $tmpName, - $ex->getMessage() + $ex->getMessage(), ); Log::warning($message); @@ -91,7 +91,7 @@ protected function clamdScan(string $tmpName): ?string $this->sendInstream($tmpName, $socket); break; default: - throw new \OutOfBoundsException(sprintf('Invalid scan mode: %s', $mode)); + throw new OutOfBoundsException(sprintf('Invalid scan mode: %s', $mode)); } return $socket->read(); @@ -104,12 +104,12 @@ protected function clamdScan(string $tmpName): ?string * @param \Cake\Network\Socket $socket socket to write * @return void */ - protected function sendInstream(string $tmpName, BaseSocket $socket): void + protected function sendInstream(string $tmpName, Socket $socket): void { $fhandler = fopen($tmpName, 'r'); $streamMaxLength = Configure::read('CakeDC/Clamav.streamMaxLength', 25 * 1024 * 1024); if (!$fhandler) { - throw new \OutOfBoundsException(sprintf('Unable to open file: %s', $tmpName)); + throw new OutOfBoundsException(sprintf('Unable to open file: %s', $tmpName)); } $socket->write('nINSTREAM' . PHP_EOL); while (!feof($fhandler)) { @@ -128,7 +128,7 @@ protected function sendInstream(string $tmpName, BaseSocket $socket): void * Get Socket instance for DI * * @param array $config socket configuration - * @return \CakeDC\Clamav\Network\Socket + * @return \Cake\Network\Socket */ protected function getSocketInstance(array $config): Socket { @@ -139,7 +139,7 @@ protected function getSocketInstance(array $config): Socket * Check scan result and return error msg or true if OK * * @param string $result result from clamad - * @return bool|string + * @return string|bool */ protected function checkScanResult(string $result): bool|string { diff --git a/tests/TestCase/Validation/ClamdValidationTest.php b/tests/TestCase/Validation/ClamdValidationTest.php index 60bd696..b6357c5 100644 --- a/tests/TestCase/Validation/ClamdValidationTest.php +++ b/tests/TestCase/Validation/ClamdValidationTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); /** - * Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * @copyright Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -17,20 +17,19 @@ use Cake\Cache\Engine\NullEngine; use Cake\Core\Configure; use Cake\Network\Exception\SocketException; +use Cake\Network\Socket; use Cake\TestSuite\TestCase; -use CakeDC\Clamav\Network\Socket; use CakeDC\Clamav\Validation\ClamdValidation; -/** - * @property ClamdValidation ClamdValidation - */ class ClamdValidationTest extends TestCase { + protected ?ClamdValidation $ClamdValidation = null; + public function setUp(): void { parent::setUp(); $this->ClamdValidation = new ClamdValidation(); - Cache::setConfig('_cake_core_', [ + Cache::setConfig('_cake_translations_', [ 'className' => NullEngine::class, ]); } @@ -38,7 +37,7 @@ public function setUp(): void public function tearDown(): void { $this->ClamdValidation = null; - Cache::drop('_cake_core_'); + Cache::drop('_cake_translations_'); parent::tearDown(); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d48b0c6..885739f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,12 +2,12 @@ declare(strict_types=1); /** - * Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright 2013 - 2023, Cake Development Corporation (https://www.cakedc.com) + * @copyright Copyright 2013 - 2026, Cake Development Corporation (https://www.cakedc.com) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */