Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Oct 27, 2024
1 parent 1fe7d66 commit bef5201
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 79 deletions.
4 changes: 3 additions & 1 deletion app/code/core/Mage/Catalog/Helper/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function __construct()
$convertNode = Mage::getConfig()->getNode('default/url/convert');
if ($convertNode) {
foreach ($convertNode->children() as $node) {
$this->_convertTable[(string) $node->from] = (string) $node->to;
if (property_exists($node, 'from') && property_exists($node, 'to')) {
$this->_convertTable[(string) $node->from] = (string) $node->to;
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions app/code/core/Mage/Catalog/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ public function getSlugger(): AsciiSlugger
return $this->slugger[$locale];
}

final public function getSluggerConfig(?string $locale, bool $useConvertTable = true): array
final public function getSluggerConfig(?string $locale): array
{
$config = [
'@' => 'at',
Expand All @@ -1067,21 +1067,19 @@ final public function getSluggerConfig(?string $locale, bool $useConvertTable =
'\u2122' => 'tm'
];

// @todo better config
$config += Mage::helper('catalog/product_url')->getConvertTable();

if ($locale) {
$configNodes = Mage::getConfig()->getNode('global/slugger/' . $locale . '/replacements');
if ($configNodes instanceof Mage_Core_Model_Config_Element) {
$convertNode = Mage::getConfig()->getNode('default/url/convert/' . $locale);
if ($convertNode instanceof Mage_Core_Model_Config_Element) {
$custom = [];
/** @var Mage_Core_Model_Config_Element $configNode */
foreach ($configNodes->children() as $configNode) {
$configNode = $configNode->asArray();
$custom[$configNode['from']] = $configNode['to'];
foreach ($convertNode->children() as $node) {

Check failure on line 1077 in app/code/core/Mage/Catalog/Model/Url.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze (ubuntu-latest, 8.4)

Variable $configNode in PHPDoc tag @var does not match any variable in the foreach loop: $node
if (property_exists($node, 'from') && property_exists($node, 'to')) {
$custom[(string) $node->from] = (string) $node->to;
}
}
$config = [$locale => $config + $custom];

if ($useConvertTable) {
$config[$locale] += Mage::helper('catalog/product_url')->getConvertTable();
}
}
}

Expand Down
116 changes: 54 additions & 62 deletions app/code/core/Mage/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,68 +184,6 @@
</observers>
</model_delete_before>
</events>
<slugger>
<de_DE>
<replacements>
<replach_percent>
<from><![CDATA[%]]></from>
<to>prozent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>und</to>
</replace_and>
</replacements>
</de_DE>
<en_US>
<replacements>
<replach_percent>
<from><![CDATA[%]]></from>
<to>percent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>and</to>
</replace_and>
</replacements>
</en_US>
<fr_FR>
<replacements>
<replach_percent>
<from><![CDATA[%]]></from>
<to>pour cent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>et</to>
</replace_and>
</replacements>
</fr_FR>
<it_IT>
<replacements>
<replach_percent>
<from><![CDATA[%]]></from>
<to>per cento</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>e</to>
</replace_and>
</replacements>
</it_IT>
<es_ES>
<replacements>
<replach_percent>
<from><![CDATA[%]]></from>
<to>por ciento</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>et</to>
</replace_and>
</replacements>
</es_ES>
</slugger>
</global>
<frontend>
<routers>
Expand Down Expand Up @@ -569,6 +507,60 @@
</disallowed_block>
</custom_layout>
</validators>
<url>
<convert>
<de_DE>
<replach_percent>
<from><![CDATA[%]]></from>
<to>prozent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>und</to>
</replace_and>
</de_DE>
<en_US>
<replach_percent>
<from><![CDATA[%]]></from>
<to>percent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>and</to>
</replace_and>
</en_US>
<fr_FR>
<replach_percent>
<from><![CDATA[%]]></from>
<to>pour cent</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>et</to>
</replace_and>
</fr_FR>
<it_IT>
<replach_percent>
<from><![CDATA[%]]></from>
<to>per cento</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>e</to>
</replace_and>
</it_IT>
<es_ES>
<replach_percent>
<from><![CDATA[%]]></from>
<to>por ciento</to>
</replach_percent>
<replace_and>
<from><![CDATA[&]]></from>
<to>et</to>
</replace_and>
</es_ES>
</convert>
</url>
</default>
<stores>
<default>
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/Mage/Catalog/Model/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ public function testGetSlugger(): void
* @group Mage_Catalog
* @group Mage_Catalog_Model
*/
public function testGetSluggerConfig($expectedResult, string $locale, bool $useConvertTable = true): void
public function testGetSluggerConfig($expectedResult, string $locale): void
{
$this->assertSame($expectedResult, $this->subject->getSluggerConfig($locale, $useConvertTable));
$result = $this->subject->getSluggerConfig($locale);
$this->assertArrayHasKey($locale, $result);
$this->assertArrayHasKey('%', $result[$locale]);
$this->assertArrayHasKey('&', $result[$locale]);
$this->assertSame('at', $result[$locale]['@']);
}

public function provideGetSluggerConfig(): Generator
Expand All @@ -101,7 +105,6 @@ public function provideGetSluggerConfig(): Generator
'&' => 'und',
]],
'de_DE',
false,
];
yield 'en_US' => [
['en_US' => [
Expand All @@ -113,7 +116,6 @@ public function provideGetSluggerConfig(): Generator
'&' => 'and',
]],
'en_US',
false,
];
yield 'fr_FR' => [
['fr_FR' => [
Expand All @@ -125,7 +127,6 @@ public function provideGetSluggerConfig(): Generator
'&' => 'et',
]],
'fr_FR',
false,
];
}
}

0 comments on commit bef5201

Please sign in to comment.