Skip to content

Commit

Permalink
Fixed some Scrutinizer issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Apr 30, 2019
1 parent 52eb50c commit 24e77db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/Plugin/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,34 +173,34 @@ private function makePluginsCode()
$this->sCssCode = '';
$this->sJsCode = '';
$this->sJsReady = '';
foreach($this->xPluginManager->getResponsePlugins() as $xPlugin)
foreach($this->xPluginManager->getResponsePlugins() as $xResponsePlugin)
{
if(($sCssCode = trim($xPlugin->getCss())))
if(($sCssCode = trim($xResponsePlugin->getCss())))
{
$this->sCssCode .= rtrim($sCssCode, " \n") . "\n";
}
if(($sJsCode = trim($xPlugin->getJs())))
if(($sJsCode = trim($xResponsePlugin->getJs())))
{
$this->sJsCode .= rtrim($sJsCode, " \n") . "\n";
}
if(($sJsReady = trim($xPlugin->getScript())))
if(($sJsReady = trim($xResponsePlugin->getScript())))
{
$this->sJsReady .= trim($sJsReady, " \n") . "\n";
}
}

$this->sJsReady = $this->render('jaxon::plugins/ready.js', ['sPluginScript' => $this->sJsReady]);
foreach($this->xPluginManager->getRequestPlugins() as $xPlugin)
foreach($this->xPluginManager->getRequestPlugins() as $xRequestPlugin)
{
if(($sJsReady = trim($xPlugin->getScript())))
if(($sJsReady = trim($xRequestPlugin->getScript())))
{
$this->sJsReady .= trim($sJsReady, " \n") . "\n";
}
}

foreach($this->xPluginManager->getPackages() as $sClass)
foreach($this->xPluginManager->getPackages() as $sPackageClass)
{
$xPackage = jaxon()->di()->get($sClass);
$xPackage = jaxon()->di()->get($sPackageClass);
if(($sCssCode = trim($xPackage->css())))
{
$this->sCssCode .= rtrim($sCssCode, " \n") . "\n";
Expand Down
37 changes: 31 additions & 6 deletions src/Request/Factory/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ public static function make($xValue)
}
}

/**
* Add quotes to a given value
*
* @param string $xValue The value to be quoted
*
* @return string
*/
private function getQuotedValue($xValue)
{
$sQuoteCharacter = "'";
return $sQuoteCharacter . $xValue . $sQuoteCharacter;
}

/**
* Get a js call to Jaxon with a single parameter
*
* @param string $sFunction The function name
* @param string $sParameter The function parameter
*
* @return string
*/
private function getJsCall($sFunction, $sParameter)
{
return 'jaxon.' . $sFunction . '(' . $this->getQuotedValue($sParameter) . ')';
}

/**
* Generate the javascript code.
*
Expand All @@ -114,23 +140,22 @@ public static function make($xValue)
public function getScript()
{
$sJsCode = '';
$sQuoteCharacter = "'";
switch($this->sType)
{
case Jaxon::FORM_VALUES:
$sJsCode = "jaxon.getFormValues(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ")";
$sJsCode = $this->getJsCall('getFormValues', $this->xValue);
break;
case Jaxon::INPUT_VALUE:
$sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").value";
$sJsCode = $this->getJsCall('$', $this->xValue) . '.value';
break;
case Jaxon::CHECKED_VALUE:
$sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").checked";
$sJsCode = $this->getJsCall('$', $this->xValue) . '.checked';
break;
case Jaxon::ELEMENT_INNERHTML:
$sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").innerHTML";
$sJsCode = $this->getJsCall('$', $this->xValue) . '.innerHTML';
break;
case Jaxon::QUOTED_VALUE:
$sJsCode = $sQuoteCharacter . addslashes($this->xValue) . $sQuoteCharacter;
$sJsCode = $this->getQuotedValue(addslashes($this->xValue));
break;
case Jaxon::BOOL_VALUE:
$sJsCode = ($this->xValue) ? 'true' : 'false';
Expand Down

0 comments on commit 24e77db

Please sign in to comment.