[TASK] Optimize ApplicationContext code 50/49350/2
authorBenni Mack <benni@typo3.org>
Wed, 3 Aug 2016 15:18:53 +0000 (17:18 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 3 Aug 2016 17:17:28 +0000 (19:17 +0200)
Use strpos() and explicit in_array() as well as fixing comments
and class inclusions.

Resolves: #77386
Releases: master
Change-Id: If72ed72dd14531cccad8be80070ce1c622cf9209
Reviewed-on: https://review.typo3.org/49350
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Core/ApplicationContext.php

index 08a5fd5..8251063 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Core;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception;
+
 /**
  * The TYPO3 Context object.
  *
@@ -57,11 +59,11 @@ class ApplicationContext
      * Initialize the context object.
      *
      * @param string $contextString
-     * @throws \Exception if the parent context is none of "Development", "Production" or "Testing"
+     * @throws Exception if the parent context is none of "Development", "Production" or "Testing"
      */
     public function __construct($contextString)
     {
-        if (strstr($contextString, '/') === false) {
+        if (strpos($contextString, '/') === false) {
             $this->rootContextString = $contextString;
             $this->parentContext = null;
         } else {
@@ -71,8 +73,8 @@ class ApplicationContext
             $this->parentContext = new ApplicationContext(implode('/', $contextStringParts));
         }
 
-        if (!in_array($this->rootContextString, array('Development', 'Production', 'Testing'))) {
-            throw new \TYPO3\CMS\Core\Exception('The given context "' . $contextString . '" was not valid. Only allowed are Development, Production and Testing, including their sub-contexts', 1335436551);
+        if (!in_array($this->rootContextString, ['Development', 'Production', 'Testing'], true)) {
+            throw new Exception('The given context "' . $contextString . '" was not valid. Only allowed are Development, Production and Testing, including their sub-contexts', 1335436551);
         }
 
         $this->contextString = $contextString;