Skip to content

Commit

Permalink
Dev: Fix some small issues and add template config to phpcs/phpmd ana…
Browse files Browse the repository at this point in the history
…lysis
  • Loading branch information
olleharstedt committed Mar 1, 2021
1 parent 6036bb2 commit db18a79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
9 changes: 2 additions & 7 deletions application/models/TemplateConfig.php
Expand Up @@ -44,7 +44,7 @@ class TemplateConfig extends CActiveRecord
/** @var string $filesPath Path of the tmeplate's files */
public $filesPath;

/** @var string[] $cssFramework What framework css is used */
/** @var object $cssFramework What framework css is used */
public $cssFramework;

/** @var boolean $isStandard Is this template a core one? */
Expand Down Expand Up @@ -198,7 +198,7 @@ protected function removeFilesFromPackage($sPackageName, $aPackage, $sType, $aFi
if (!empty($aPackage[$sType])) {
if (!empty($aFilesToRemove)) {
foreach ($aFilesToRemove as $sFileToRemove) {
if (($key = array_search($sFileToRemove, $aPackage[$sType])) !== false) {
if (array_search($sFileToRemove, $aPackage[$sType]) !== false) {
App()->clientScript->removeFileFromPackage($sPackageName, $sType, $sFileToRemove);
}
}
Expand Down Expand Up @@ -1004,9 +1004,6 @@ public static function uninstall($templatename)
$oTemplate = Template::model()->findByAttributes(array('name' => $templatename));
if ($oTemplate) {
if ($oTemplate->delete()) {
$oTemplateConfig = TemplateConfiguration::model()->findByAttributes(
array('template_name' => $templatename)
);
return TemplateConfiguration::model()->deleteAll(
'template_name=:templateName',
array(':templateName' => $templatename)
Expand Down Expand Up @@ -1235,8 +1232,6 @@ public function getTemplateForAsset($sFile, $oRTemplate)

$oMotherTemplate = $oRTemplate->oMotherTemplate;
$oRTemplate = $oMotherTemplate;
$sPackageName = $oRTemplate->sPackageName;

$sFilePath = Yii::getPathOfAlias(
App()->clientScript->packages[$oRTemplate->sPackageName]["basePath"]
) . DIRECTORY_SEPARATOR . $sFile;
Expand Down
21 changes: 6 additions & 15 deletions application/models/TemplateManifest.php
Expand Up @@ -98,7 +98,6 @@ public function getScreensDetails()
foreach ($oScreensFromXML[0] as $sScreen => $oScreen) {
// We reset LayoutName and FileName at each loop to avoid errors
$sLayoutName = "";
$sFileName = "";
$sTitle = "";

foreach ($oScreen as $sKey => $oField) {
Expand Down Expand Up @@ -206,11 +205,7 @@ public function getDefaultDataForRendering($thissurvey = array())

public function getDefaultDataForLanguageChanger($thissurvey = array())
{

$thissurvey = empty($thissurvey) ? array() : $thissurvey;
$oDataFromXML = $this->templateEditor->default_data->xpath('//survey_data');


$thissurvey['alanguageChanger']['datas'] = [
'sSelected' => 'en',
//'withForm' => true, // Set to true for no-js functionality.
Expand Down Expand Up @@ -980,7 +975,7 @@ public static function extendsConfig($sToExtends, $sNewName)

// First we get the XML file
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(false);
libxml_disable_entity_loader(false);
}
$oNewManifest = self::getManifestDOM($sConfigPath);

Expand All @@ -994,7 +989,7 @@ public static function extendsConfig($sToExtends, $sNewName)
$oNewManifest->save($sConfigPath . "/config.xml");

if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(true);
libxml_disable_entity_loader(true);
}
}

Expand Down Expand Up @@ -1166,7 +1161,7 @@ public function addFileReplacement($sFile, $sType)
$oConfig->insertBefore($oFiles, $oOptions);
$oNewManifest->save($this->path . "config.xml");
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(true);
libxml_disable_entity_loader(true);
}
}

Expand All @@ -1179,9 +1174,7 @@ public function addFileReplacement($sFile, $sType)
protected function getFilesTo($oTemplate, $sType, $sAction)
{
$aFiles = array();
$oRFilesTemplate = (!empty($bExtends)) ? self::getTemplateForXPath($oTemplate, 'files') : $oTemplate;

if (isset($oRFilesTemplate->config->files->$sType->$sAction)) {
if (isset($oTemplate->config->files->$sType->$sAction)) {
$aFiles = (array) $oTemplate->config->files->$sType->$sAction;
}

Expand Down Expand Up @@ -1322,8 +1315,6 @@ public static function getAssetsToReplaceFormated($oEngine, $sType, $bInlcudeRem
{
$oAssetsToReplaceFormated = new stdClass();
if (!empty($oEngine->cssframework->$sType) && !empty($oEngine->cssframework->$sType->attributes()->replace)) {
//var_dump($oEngine->cssframework->$sType); die();

$sAssetsToReplace = (string) $oEngine->cssframework->$sType->attributes()->replace;
$sAssetsReplacement = (string) $oEngine->cssframework->$sType;

Expand Down Expand Up @@ -1381,14 +1372,14 @@ public static function getOptionAttributes($path)
{
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(false);
}
}
$file = realpath($path . "config.xml");
if (file_exists($file)) {
$sXMLConfigFile = file_get_contents($file);
$oXMLConfig = simplexml_load_string($sXMLConfigFile);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(true);
}
}
$aOptions['categories'] = array();

foreach ($oXMLConfig->options->children() as $key => $option) {
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Expand Up @@ -49,7 +49,13 @@
"! find application/ -type f -name '*.php' -print0 | xargs -I {} -0 -P 0 php -l {} | grep -v 'No syntax error'",
"! find tests/ -type f -name '*.php' -print0 | xargs -I {} -0 -P 0 php -l {} | grep -v 'No syntax error'",
"./third_party/bin/phpcs --standard=tests/rulesets/phpcs_ruleset.xml application/models/services",
"./third_party/bin/phpcs --standard=tests/rulesets/phpcs_ruleset.xml application/models/TemplateManifest.php",
"./third_party/bin/phpcs --standard=tests/rulesets/phpcs_ruleset.xml application/models/TemplateConfiguration.php",
"./third_party/bin/phpcs --standard=tests/rulesets/phpcs_ruleset.xml application/models/TemplateConfig.php",
"./third_party/bin/phpmd application/models/services/ text tests/rulesets/phpmd_ruleset.xml",
"./third_party/bin/phpmd application/models/TemplateConfig.php text tests/rulesets/phpmd_ruleset.xml",
"./third_party/bin/phpmd application/models/TemplateConfiguration.php text tests/rulesets/phpmd_ruleset.xml",
"./third_party/bin/phpmd application/models/TemplateManifest.php text tests/rulesets/phpmd_ruleset.xml",
"./third_party/bin/psalm application/models/services/"
]
}
Expand Down

0 comments on commit db18a79

Please sign in to comment.