diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 85e023d..94cd760 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -14,10 +14,10 @@ jobs:
strategy:
fail-fast: false
matrix:
- php-version: ['7.4', '8.2']
+ php-version: ['8.1', '8.2']
prefer-lowest: ['']
include:
- - php-version: '7.4'
+ - php-version: '8.1'
prefer-lowest: 'prefer-lowest'
steps:
@@ -55,17 +55,17 @@ jobs:
fi
- name: Setup problem matchers for PHPUnit
- if: matrix.php-version == '7.4'
+ if: matrix.php-version == '8.1'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run PHPUnit
run: |
- if [[ ${{ matrix.php-version }} == '7.4' ]]; then
- export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
+ if [[ ${{ matrix.php-version }} == '8.1' ]]; then
+ export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
- if: matrix.php-version == '7.4'
+ if: matrix.php-version == '8.1'
uses: codecov/codecov-action@v1
diff --git a/.gitignore b/.gitignore
index 52c8085..4434dac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.DS_Store
+.phpunit.result.cache
/vendor
/composer.lock
diff --git a/.stickler.yml b/.stickler.yml
deleted file mode 100644
index bfc37d6..0000000
--- a/.stickler.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-linters:
- phpcs:
- standard: CakePHP
- fixer: true
-files:
- ignore:
- - 'vendor/*'
-fixers:
- enable: true
diff --git a/composer.json b/composer.json
index de5d7f9..79ae094 100644
--- a/composer.json
+++ b/composer.json
@@ -27,14 +27,18 @@
}
},
"require": {
- "php": ">=7.4.0",
- "cakephp/cakephp": "^4.0",
- "cakephp/plugin-installer": "*",
- "geshi/geshi": "^1.0"
+ "php": ">=8.1",
+ "cakephp/cakephp": "^5.0",
+ "cakephp/plugin-installer": "^2.0.1",
+ "geshi/geshi": "^1.0.9.1"
},
"require-dev": {
- "phpunit/phpunit": "^8",
- "cakephp/cakephp-codesniffer": "^4.0"
+ "phpunit/phpunit": "^10.1.0 <=10.5.3",
+ "cakephp/cakephp-codesniffer": "^5.0"
+ },
+ "scripts": {
+ "cs-check": "phpcs --colors -p src/ tests/",
+ "cs-fix": "phpcbf --colors -p src/ tests/"
},
"prefer-stable": true,
"config": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index c585318..600a824 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -13,4 +13,11 @@
./tests/TestCase
+
+
+
diff --git a/src/Plugin.php b/src/Plugin.php
index 03c06f9..a4cdda2 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -15,5 +15,5 @@ class Plugin extends BasePlugin
*
* @var string
*/
- protected $name = 'Geshi';
+ protected ?string $name = 'Geshi';
}
diff --git a/src/View/Helper/GeshiHelper.php b/src/View/Helper/GeshiHelper.php
index ad3d01e..fa7a322 100644
--- a/src/View/Helper/GeshiHelper.php
+++ b/src/View/Helper/GeshiHelper.php
@@ -17,9 +17,7 @@
use Cake\View\Helper;
use Cake\View\StringTemplateTrait;
-use Cake\View\View;
use GeSHi;
-use InvalidArgumentException;
/**
* Expose Geshi Syntax highlighting in a CakePHP application.
@@ -47,7 +45,7 @@ class GeshiHelper extends Helper
*
* @param array
*/
- protected $_defaultConfig = [
+ protected array $_defaultConfig = [
'configPath' => '',
'features' => [],
'validContainers' => ['pre'],
@@ -74,38 +72,7 @@ class GeshiHelper extends Helper
*
* @var \GeSHi|null
*/
- protected $_geshi = null;
-
- /**
- * Magic getter for backwards compatibility with public variables.
- *
- * @param string $name The attribute to read
- * @return mixed
- */
- public function __get(string $name)
- {
- if (!array_key_exists($name, $this->_defaultConfig)) {
- throw new InvalidArgumentException("Invalid configuration key {$name}");
- }
-
- return $this->getConfig($name);
- }
-
- /**
- * Magic setter for backwards compatibility with public variables.
- *
- * @param string $name The attribute to set
- * @param mixed $value The attribute value
- * @return void
- */
- public function __set(string $name, $value)
- {
- if (!array_key_exists($name, $this->_defaultConfig)) {
- throw new InvalidArgumentException("Invalid configuration key {$name}");
- }
-
- $this->setConfig($name, $value, false);
- }
+ protected ?GeSHi $_geshi = null;
/**
* Highlight a block of HTML containing defined blocks. Converts blocks from plain text
@@ -139,7 +106,7 @@ public function highlight(string $htmlString)
* @param bool $withStylesheet If true will include GeSHi's generated stylesheet.
* @return string Highlighted HTML.
*/
- public function highlightText(string $text, string $language, bool $withStylesheet = false)
+ public function highlightText(string $text, string $language, bool $withStylesheet = false): string
{
$this->_getGeshi();
$this->_geshi->set_source($text);
@@ -159,7 +126,7 @@ public function highlightText(string $text, string $language, bool $withStyleshe
* @param string $language The language to highlight as.
* @return string Highlighted HTML.
*/
- public function highlightAsTable($text, $language)
+ public function highlightAsTable(string $text, string $language): string
{
$this->_getGeshi();
$this->_geshi->set_source($text);
@@ -219,7 +186,7 @@ protected function _getGeshi()
* @param array $matches code block groups
* @return string Completed replacement string
*/
- protected function _processCodeBlock(array $matches)
+ protected function _processCodeBlock(array $matches): string
{
[$block, $openTag, $tagName, $lang, $code, $closeTag] = $matches;
unset($matches);
@@ -260,7 +227,7 @@ protected function _processCodeBlock(array $matches)
* @param string $lang Language
* @return string|null
*/
- public function validLang(string $lang)
+ public function validLang(string $lang): ?string
{
if (in_array($lang, $this->_config['validLanguages'])) {
return $lang;
@@ -280,7 +247,7 @@ public function validLang(string $lang)
* @param \GeSHi $geshi Geshi instance
* @return void
*/
- protected function _configureInstance(GeSHi $geshi)
+ protected function _configureInstance(GeSHi $geshi): void
{
if (empty($this->_config['features'])) {
if (empty($this->_config['configPath'])) {
@@ -310,7 +277,7 @@ protected function _configureInstance(GeSHi $geshi)
*
* @return string
*/
- protected function _includeStylesheet()
+ protected function _includeStylesheet(): string
{
$template = <<
diff --git a/tests/TestCase/Helper/GeshiHelperTest.php b/tests/TestCase/Helper/GeshiHelperTest.php
index e5afd90..1c1cb94 100644
--- a/tests/TestCase/Helper/GeshiHelperTest.php
+++ b/tests/TestCase/Helper/GeshiHelperTest.php
@@ -9,15 +9,16 @@
class GeshiHelperTest extends TestCase
{
- protected $settings = [
+ protected array $settings = [
'set_header_type' => ['GESHI_HEADER_NONE'],
'enable_line_numbers' => ['GESHI_FANCY_LINE_NUMBERS', 2],
'enable_classes' => [],
'set_tab_width' => [4],
];
- protected $view;
- protected $configPath;
+ protected View $view;
+ protected GeshiHelper $geshi;
+ protected string $configPath;
public function setUp(): void
{
@@ -26,7 +27,8 @@ public function setUp(): void
$this->view = $this->getMockBuilder(View::class)->getMock();
$this->geshi = new GeshiHelper($this->view);
- $this->configPath = $this->geshi->configPath = dirname(dirname(dirname(__FILE__))) . DS;
+ $this->configPath = dirname(dirname(dirname(__FILE__))) . DS;
+ $this->geshi->setConfig('configPath', $this->configPath);
}
public function tearDown(): void
@@ -44,20 +46,18 @@ public function runVariants($method)
{
// Using a config file, traditional.
$this->geshi = new GeshiHelper($this->view);
- $this->geshi->configPath = $this->configPath;
+ $this->geshi->setConfig('configPath', $this->configPath);
call_user_func([$this, $method]);
unset($this->geshi);
// Pre-configuration during instantiation, such as from controller.
- $this->geshi = new GeshiHelper($this->view, $this->settings);
- unset($this->geshi->configPath);
+ $this->geshi = new GeshiHelper($this->view, ['features' => $this->settings]);
call_user_func([$this, $method]);
unset($this->geshi);
// Configuration on the fly, such as from view.
$this->geshi = new GeshiHelper($this->view);
- unset($this->geshi->configPath);
- $this->geshi->features = $this->settings;
+ $this->geshi->setConfig('features', $this->settings);
call_user_func([$this, $method]);
unset($this->geshi);
}
@@ -79,7 +79,7 @@ public function testConfigVariants()
*/
public function testHighlight()
{
- $this->geshi->showPlainTextButton = false;
+ $this->geshi->setConfig('showPlainTextButton', false);
// Simple one code block
$text = '
This is some text
More text
';
@@ -165,7 +165,7 @@ public function testHighlight()
$this->assertHtml($expected, $result);
// More than one valid code block container
- $this->geshi->validContainers = ['pre', 'code'];
+ $this->geshi->setConfig('validContainers', ['pre', 'code'], false);
$text = 'Text
echo $foo = "foo";
';
$result = $this->geshi->highlight($text);
$expected = [
@@ -202,8 +202,8 @@ public function testHighlight()
$this->assertHtml($expected, $result, true);
// No valid languages no highlights
- $this->geshi->validContainers = ['pre'];
- $this->geshi->validLanguages = [];
+ $this->geshi->setConfig('validContainers', ['pre']);
+ $this->geshi->setConfig('validLanguages', [], false);
$text = 'text
echo $foo;
text
';
$result = $this->geshi->highlight($text);
$expected = [
@@ -252,8 +252,8 @@ public function testPlainTextButton()
public function testNoTagReplacement()
{
// Simple one code block
- $this->geshi->showPlainTextButton = false;
- $this->geshi->containerMap = [];
+ $this->geshi->setConfig('showPlainTextButton', false);
+ $this->geshi->setConfig('containerMap', [], false);
$text = 'This is some text
More text
';
$result = $this->geshi->highlight($text);
@@ -347,8 +347,8 @@ public function testTemplates()
// The button element and wrappers used for showPlainTextButton
'showplain' => 'Plain Text',
]);
- $this->geshi->validContainers = ['pre'];
- $this->geshi->validLanguages = [];
+ $this->geshi->setConfig('validContainers', ['pre']);
+ $this->geshi->setConfig('validLanguages', [], false);
$text = 'text
echo $foo;
text
';
$result = $this->geshi->highlight($text);
$expected = [