Skip to content

Commit 1d7a8da

Browse files
authored
IBX-8875: Dropped deprecated code (#185)
* Dropped deprecated OnlineEditorCustomAttributesExtractor class * Defined Xslt::$xsltProcessor property so it's not dynamic. Creation of dynamic property Ibexa\FieldTypeRichText\RichText\Converter\Xslt::$xsltProcessor is deprecated * Improved quality of Xslt Converter implementation * Dropped deprecated support for not configured custom tag. CustomTagsValidator will now return a validation error when a document contains not configured custom tag * Improved CustomTagsValidator class code quality * [Tests] Improved CustomTagsValidatorTest and RichTextTest code quality * [PHPStan] Aligned baseline with the changes
1 parent bf49c56 commit 1d7a8da

File tree

11 files changed

+29
-230
lines changed

11 files changed

+29
-230
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,6 @@ parameters:
890890
count: 1
891891
path: src/lib/RichText/Converter/Render/Template.php
892892

893-
-
894-
message: "#^Access to an undefined property Ibexa\\\\FieldTypeRichText\\\\RichText\\\\Converter\\\\Xslt\\:\\:\\$xsltProcessor\\.$#"
895-
count: 1
896-
path: src/lib/RichText/Converter/Xslt.php
897-
898893
-
899894
message: "#^Cannot access property \\$firstChild on DOMElement\\|null\\.$#"
900895
count: 1
@@ -905,31 +900,11 @@ parameters:
905900
count: 1
906901
path: src/lib/RichText/Converter/Xslt.php
907902

908-
-
909-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\RichText\\\\Converter\\\\Xslt\\:\\:__construct\\(\\) has parameter \\$customStylesheets with no value type specified in iterable type array\\.$#"
910-
count: 1
911-
path: src/lib/RichText/Converter/Xslt.php
912-
913-
-
914-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\RichText\\\\Converter\\\\Xslt\\:\\:convert\\(\\) should return DOMDocument but returns DOMDocument\\|false\\.$#"
915-
count: 1
916-
path: src/lib/RichText/Converter/Xslt.php
917-
918-
-
919-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\RichText\\\\Converter\\\\Xslt\\:\\:getSortedCustomStylesheets\\(\\) return type has no value type specified in iterable type array\\.$#"
920-
count: 1
921-
path: src/lib/RichText/Converter/Xslt.php
922-
923903
-
924904
message: "#^Parameter \\#1 \\$source of method DOMDocument\\:\\:loadXML\\(\\) expects string, string\\|false given\\.$#"
925905
count: 1
926906
path: src/lib/RichText/Converter/Xslt.php
927907

928-
-
929-
message: "#^Property Ibexa\\\\FieldTypeRichText\\\\RichText\\\\Converter\\\\Xslt\\:\\:\\$customStylesheets type has no value type specified in iterable type array\\.$#"
930-
count: 1
931-
path: src/lib/RichText/Converter/Xslt.php
932-
933908
-
934909
message: "#^Cannot call method lookupNamespaceURI\\(\\) on DOMElement\\|null\\.$#"
935910
count: 2
@@ -1245,11 +1220,6 @@ parameters:
12451220
count: 1
12461221
path: src/lib/RichText/XmlBase.php
12471222

1248-
-
1249-
message: "#^Parameter \\#2 \\$desc of method Ibexa\\\\FieldTypeRichText\\\\Translation\\\\Extractor\\\\OnlineEditorCustomAttributesExtractor\\:\\:createMessage\\(\\) expects string, int\\|string given\\.$#"
1250-
count: 1
1251-
path: src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php
1252-
12531223
-
12541224
message: "#^Property Ibexa\\\\FieldTypeRichText\\\\Validator\\\\Constraints\\\\RichText\\:\\:\\$message has no type specified\\.$#"
12551225
count: 1
@@ -2935,11 +2905,6 @@ parameters:
29352905
count: 1
29362906
path: tests/lib/RichText/Validator/CustomTagsValidatorTest.php
29372907

2938-
-
2939-
message: "#^Method Ibexa\\\\Tests\\\\FieldTypeRichText\\\\RichText\\\\Validator\\\\CustomTagsValidatorTest\\:\\:testValidateDocumentAcceptsLegacyTags\\(\\) has no return type specified\\.$#"
2940-
count: 1
2941-
path: tests/lib/RichText/Validator/CustomTagsValidatorTest.php
2942-
29432908
-
29442909
message: "#^Call to method validateDocument\\(\\) on an unknown class Ibexa\\\\FieldTypeRichText\\\\RichText\\\\ValidatorInterface\\.$#"
29452910
count: 1

src/bundle/Resources/config/fieldtype_services.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ services:
7373

7474
# Note: should typically be the last one as it produces embeddable fragment
7575
Ibexa\FieldTypeRichText\RichText\Converter\Xslt:
76-
class: Ibexa\FieldTypeRichText\RichText\Converter\Xslt
7776
arguments: ['%ibexa.field_type.richtext.converter.output.xhtml5.fragment.resources%']
7877
tags:
7978
- {name: ibexa.field_type.richtext.converter.output.xhtml5, priority: 100}

src/bundle/Resources/config/translation.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ services:
44
autoconfigure: true
55
public: false
66

7-
Ibexa\FieldTypeRichText\Translation\Extractor\OnlineEditorCustomAttributesExtractor:
8-
deprecated: 'Since ibexa/fieldtype-richtext 4.6.7 the "%service_id%" service is deprecated, will be removed in 5.0.0'
9-
arguments:
10-
$siteAccessList: '%ibexa.site_access.list%'
11-
tags:
12-
- { name: jms_translation.extractor, alias: ez_online_editor_attributes }
13-
147
Ibexa\FieldTypeRichText\Translation\Extractor\CustomTagExtractor:
158
arguments:
169
$customTags: '%ibexa.field_type.richtext.custom_tags%'

src/lib/RichText/Converter/Html5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class Html5 extends XsltConverter
1818
{
19-
public function __construct($stylesheet, ConfigResolverInterface $configResolver)
19+
public function __construct(string $stylesheet, ConfigResolverInterface $configResolver)
2020
{
2121
$customStylesheets = $configResolver->getParameter('fieldtypes.ezrichtext.output_custom_xsl');
2222
$customStylesheets = $customStylesheets ?: [];

src/lib/RichText/Converter/Html5Edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class Html5Edit extends XsltConverter
1818
{
19-
public function __construct($stylesheet, ConfigResolverInterface $configResolver)
19+
public function __construct(string $stylesheet, ConfigResolverInterface $configResolver)
2020
{
2121
$customStylesheets = $configResolver->getParameter('fieldtypes.ezrichtext.edit_custom_xsl');
2222
$customStylesheets = $customStylesheets ?: [];

src/lib/RichText/Converter/Html5Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class Html5Input extends XsltConverter
1818
{
19-
public function __construct($stylesheet, ConfigResolverInterface $configResolver)
19+
public function __construct(string $stylesheet, ConfigResolverInterface $configResolver)
2020
{
2121
$customStylesheets = $configResolver->getParameter('fieldtypes.ezrichtext.input_custom_xsl');
2222
$customStylesheets = $customStylesheets ?: [];

src/lib/RichText/Converter/Xslt.php

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,39 @@ class Xslt extends XmlBase implements Converter
2222
{
2323
/**
2424
* Path to stylesheet to use.
25-
*
26-
* @var string
2725
*/
28-
protected $stylesheet;
26+
protected string $stylesheet;
2927

3028
/**
3129
* Array of XSL stylesheets to add to the main one, grouped by priority.
3230
*
33-
* @var array
31+
* @var array<int, array<string>>
3432
*/
35-
protected $customStylesheets = [];
33+
protected array $customStylesheets = [];
34+
35+
private XSLTProcessor $xsltProcessor;
3636

3737
/**
38-
* Constructor.
39-
*
4038
* @param string $stylesheet Stylesheet to use for conversion
41-
* @param array $customStylesheets Array of XSL stylesheets. Each entry consists in a hash having "path" and "priority" keys.
39+
* @param array<array{priority: int, path: string}> $customStylesheets Array of XSL stylesheets. Each entry consists in a hash having "path" and "priority" keys.
4240
*/
43-
public function __construct($stylesheet, array $customStylesheets = [])
41+
public function __construct(string $stylesheet, array $customStylesheets = [])
4442
{
4543
$this->stylesheet = $stylesheet;
4644

4745
// Grouping stylesheets by priority.
4846
foreach ($customStylesheets as $customStylesheet) {
49-
$this->customStylesheets[$customStylesheet['priority']][] = $customStylesheet['path'];
47+
$this->customStylesheets[(int)$customStylesheet['priority']][] = $customStylesheet['path'];
5048
}
5149
}
5250

5351
/**
5452
* Returns the XSLTProcessor to use to transform internal XML to HTML5.
5553
*
5654
* @throws \RuntimeException
57-
*
58-
* @return \XSLTProcessor
55+
* @throws \DOMException
5956
*/
60-
protected function getXSLTProcessor()
57+
protected function getXSLTProcessor(): XSLTProcessor
6158
{
6259
if (isset($this->xsltProcessor)) {
6360
return $this->xsltProcessor;
@@ -97,30 +94,23 @@ protected function getXSLTProcessor()
9794
* The order is from the lowest priority to the highest since in case of a conflict,
9895
* the last loaded XSL template always wins.
9996
*
100-
* @return array
97+
* @return list<string>
10198
*/
102-
protected function getSortedCustomStylesheets()
99+
protected function getSortedCustomStylesheets(): array
103100
{
104-
$sortedStylesheets = [];
105101
ksort($this->customStylesheets);
106-
foreach ($this->customStylesheets as $stylesheets) {
107-
$sortedStylesheets = array_merge($sortedStylesheets, $stylesheets);
108-
}
109102

110-
return $sortedStylesheets;
103+
// flatten [priority => stylesheet[]] array to return a simple list
104+
return array_merge(...$this->customStylesheets);
111105
}
112106

113107
/**
114108
* Performs conversion of the given $document using XSLT stylesheet.
115109
*
116-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if stylesheet is not found
117-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if document does not transform
118-
*
119-
* @param \DOMDocument $document
120-
*
121-
* @return \DOMDocument
110+
* @throws \DOMException
111+
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
122112
*/
123-
public function convert(DOMDocument $document)
113+
public function convert(DOMDocument $xmlDoc): DOMDocument
124114
{
125115
if (!file_exists($this->stylesheet)) {
126116
throw new InvalidArgumentException(
@@ -133,11 +123,11 @@ public function convert(DOMDocument $document)
133123

134124
$this->startRecordingErrors();
135125

136-
$document = $processor->transformToDoc($document);
126+
$document = $processor->transformToDoc($xmlDoc);
137127

138128
$errors = $this->collectErrors();
139129

140-
if (!empty($errors)) {
130+
if (!empty($errors) || $document === false) {
141131
throw new InvalidArgumentException(
142132
'$xmlDoc',
143133
'Transformation of XML content failed: ' . implode("\n", $errors)

src/lib/RichText/Validator/CustomTagsValidator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public function validateDocument(DOMDocument $xmlDocument): array
5757
}
5858

5959
if (!isset($this->customTagsConfiguration[$tagName])) {
60-
@trigger_error(
61-
"Configuration for RichText Custom Tag '{$tagName}' not found. " .
62-
'Custom Tags configuration is required since 7.1, its lack will result in validation error in 8.x',
63-
E_USER_DEPRECATED
64-
);
60+
$errors[] = "Missing configuration for RichText CustomTag: '$tagName'";
6561
continue;
6662
}
6763

@@ -92,7 +88,7 @@ public function validateDocument(DOMDocument $xmlDocument): array
9288
continue;
9389
}
9490

95-
if (!in_array($attributeName, $nonEmptyAttributes)) {
91+
if (!in_array($attributeName, $nonEmptyAttributes, true)) {
9692
$errors[] = "The attribute '{$attributeName}' of RichText Custom Tag '{$tagName}' cannot be empty";
9793
}
9894
}

src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

tests/bundle/DependencyInjection/Configuration/Parser/FieldType/RichTextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function configureAndLoad(array $configurationValues = [])
6969

7070
$extensionAlias = $extension->getAlias();
7171
// when loading extension, pass only relevant configuration
72-
$extensionConfig = isset($configs[$extensionAlias]) ? $configs[$extensionAlias] : [];
72+
$extensionConfig = $configs[$extensionAlias] ?? [];
7373

7474
$extension->load([$extensionConfig], $this->container);
7575
}

0 commit comments

Comments
 (0)