Skip to content

Commit

Permalink
[TASK] Small changes in code with php 7.0 features
Browse files Browse the repository at this point in the history
  • Loading branch information
OttoAndras committed Nov 29, 2017
1 parent f5e3bca commit c65142b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Classes/Domain/Model/DataAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function ensureValue($value){
/**
* @return string
*/
public function getName()
public function getName() :string
{
if(substr($this->name, 0, 5) !== 'data-') {
return self::NAME_PREFIX . $this->name;
Expand All @@ -137,23 +137,23 @@ public function getName()
/**
* @param string $name
*/
public function setName($name)
public function setName(string $name)
{
$this->ensureName($name);
}

/**
* @return string
*/
public function getValue()
public function getValue() :string
{
return $this->value;
}

/**
* @param string $value
*/
public function setValue($value)
public function setValue(string $value)
{
$this->ensureValue($value);
}
Expand Down
42 changes: 21 additions & 21 deletions Classes/Domain/Model/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function ensureDataAttributes($definition) {
/**
* @return string
*/
public function getSrc()
public function getSrc() :string
{
return $this->src;
}
Expand All @@ -261,47 +261,47 @@ public function getSrc()
* @param string $src
* @return void
*/
public function setSrc($src)
public function setSrc(string $src)
{
$this->ensureSrc($src);
}

/**
* @return string
*/
public function getClass()
public function getClass() :string
{
return $this->class;
}

/**
* @param string $class
*/
public function setClass($class)
public function setClass(string $class)
{
$this->class = $class;
}

/**
* @return string
*/
public function getName()
public function getName() :string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}

/**
* @return int
*/
public function getWidth()
public function getWidth() :int
{
return $this->width;
}
Expand All @@ -310,87 +310,87 @@ public function getWidth()
* @param int $width
* @return void
*/
public function setWidth($width)
public function setWidth(int $width)
{
$this->ensureWidth($width);
}

/**
* @return int
*/
public function getHeight()
public function getHeight() :int
{
return $this->height;
}

/**
* @param int $height
*/
public function setHeight($height)
public function setHeight(int $height)
{
$this->ensureHeight($height);
}

/**
* @return array
*/
public function getSandbox()
public function getSandbox() :array
{
return $this->sandbox;
}

/**
* @param string $sandbox
*/
public function setSandbox($sandbox)
public function setSandbox(string $sandbox)
{
$this->ensureSandboxValues($sandbox);
}

/**
* @return boolean
*/
public function isAllowFullScreen()
public function isAllowFullScreen() :bool
{
return $this->allowFullScreen;
}

/**
* @param boolean $allowFullScreen
*/
public function setAllowFullScreen($allowFullScreen)
public function setAllowFullScreen(bool $allowFullScreen)
{
$this->ensureAllowFullScreen(boolval($allowFullScreen));
$this->ensureAllowFullScreen($allowFullScreen);
}

/**
* @return boolean
*/
public function isAllowPaymentRequest()
public function isAllowPaymentRequest() :bool
{
return $this->allowPaymentRequest;
}

/**
* @param boolean $allowPaymentRequest
*/
public function setAllowPaymentRequest($allowPaymentRequest)
public function setAllowPaymentRequest(bool $allowPaymentRequest)
{
$this->ensureAllowPaymentRequest(boolval($allowPaymentRequest));
$this->ensureAllowPaymentRequest($allowPaymentRequest);
}

/**
* @return array
*/
public function getDataAttributes()
public function getDataAttributes() :array
{
return $this->dataAttributes;
}

/**
* @param string $dataAttributes
*/
public function setDataAttributes($dataAttributes)
public function setDataAttributes(string $dataAttributes)
{
$this->ensureDataAttributes($dataAttributes);
}
Expand All @@ -401,7 +401,7 @@ public function setDataAttributes($dataAttributes)
* @return string
* @throws InvalidValueException
*/
public function generateHtmlTag(){
public function generateHtmlTag() {
$attributes = [];
if($this->getSrc()) {
$attributes['src'] = $this->getSrc();
Expand Down
4 changes: 1 addition & 3 deletions Classes/Hooks/TypoScriptFrontendControllerHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public function contentPostProcAll($pObjArray)
if(isset($pObjArray['pObj'])) {
/** @var TypoScriptFrontendController $typoScriptFrontendController */
$typoScriptFrontendController = $pObjArray['pObj'];
$enabled = isset($typoScriptFrontendController->config['config']['csp.']['enabled'])
? boolval($typoScriptFrontendController->config['config']['csp.']['enabled'])
: false;
$enabled = boolval($typoScriptFrontendController->config['config']['csp.']['enabled'] ?? false);

if($enabled) {

Expand Down
15 changes: 6 additions & 9 deletions Classes/Service/ContentSecurityPolicyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ static public function isNonceModeEnabled() {
* @throws InvalidClassException
*/
static private function createNewBuilderInstance() {
$className = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['csp']['ContentSecurityPolicyHeaderBuilder'])
? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['csp']['ContentSecurityPolicyHeaderBuilder']
: ContentSecurityPolicyHeaderBuilder::class;
$className = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['csp']['ContentSecurityPolicyHeaderBuilder'] ??
ContentSecurityPolicyHeaderBuilder::class;

/** @var ContentSecurityPolicyHeaderBuilderInterface $instance */
$instance = GeneralUtility::makeInstance($className);
Expand Down Expand Up @@ -161,9 +160,7 @@ static public function reloadConfig() {
*/
static public function addTypoScriptSettings($tsfe) {

$enabled = isset($tsfe->config['config']['csp.']['enabled'])
? boolval($tsfe->config['config']['csp.']['enabled'])
: false;
$enabled = boolval($tsfe->config['config']['csp.']['enabled'] ?? false);

if($enabled) {

Expand All @@ -182,7 +179,7 @@ static public function addTypoScriptSettings($tsfe) {
&& is_array($config['presets.'])) {

foreach ($config['presets.'] as $preSet) {
$preSetEnabled = isset($preSet['enabled']) ? boolval($preSet['enabled']) : false;
$preSetEnabled = boolval($preSet['enabled'] ?? false);
if ($preSetEnabled
&& isset($preSet['rules.'])
) {
Expand All @@ -203,8 +200,8 @@ static public function extractHeaders() {
$responseHeader = '';
$headers = self::getBuilder()->getHeader();
if(count($headers) > 1) {
$name = isset($headers['name']) ? $headers['name'] : '';
$value = isset($headers['value']) ? $headers['value'] : '';;
$name = $headers['name'] ?? '';
$value = $headers['value'] ?? '';

$responseHeader = $name . ': ' . $value;
}
Expand Down
18 changes: 9 additions & 9 deletions Classes/Utility/IframeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class IframeUtility
* @return string
*/
static public function generateIframeTagFromConfigArray($conf){
$src = isset($conf['src']) ? $conf['src'] : '';
$class = isset($conf['class']) ? $conf['class'] : '';
$name = isset($conf['name']) ? $conf['name'] : '';
$width = isset($conf['width']) ? $conf['width'] : 0;
$height = isset($conf['height']) ? $conf['height'] : 0;
$sandbox = isset($conf['sandbox']) ? $conf['sandbox'] : '';
$allowFullScreen = isset($conf['allowFullScreen']) ? $conf['allowFullScreen'] : '';
$allowPaymentRequest = isset($conf['allowPaymentRequest']) ? $conf['allowPaymentRequest'] : '';
$dataAttributes = isset($conf['dataAttributes']) ? $conf['dataAttributes'] : '';
$src = $conf['src'] ?? '';
$class = $conf['class'] ?? '';
$name = $conf['name'] ?? '';
$width = $conf['width'] ?? 0;
$height = $conf['height'] ?? 0;
$sandbox = $conf['sandbox'] ?? '';
$allowFullScreen = $conf['allowFullScreen'] ?? '';
$allowPaymentRequest = $conf['allowPaymentRequest'] ?? '';
$dataAttributes = $conf['dataAttributes'] ?? '';


$iframe = new Iframe($src, $class, $name, $width, $height, $sandbox, $allowFullScreen, $allowPaymentRequest, $dataAttributes);
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/ScriptViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function render($hashMethod = 'sha256')
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$output = $renderChildrenClosure();
$hashMethod = isset($arguments['hashMethod']) ? $arguments['hashMethod'] : '';
$hashMethod = $arguments['hashMethod'] ?? '';

if($hashMethod) {
$output = ScriptUtility::getValidScriptTag($output, $hashMethod, true);
Expand Down

0 comments on commit c65142b

Please sign in to comment.