HippoPHP\Hippo\Config\Config::get PHP Method

get() public method

public get ( string $key, mixed $defaultValue = null ) : mixed
$key string
$defaultValue mixed
return mixed
    public function get($key, $defaultValue = null)
    {
        if (func_num_args() === 1) {
            $current =& $this->navigateToKey($key, false);
        } else {
            try {
                $current =& $this->navigateToKey($key, false);
            } catch (BadConfigKeyException $e) {
                return $defaultValue;
            }
        }
        return is_array($current) ? new self($current) : $current;
    }

Usage Example

Beispiel #1
0
 /**
  * checkFileInternal(): defined by AbstractCheck.
  *
  * @see AbstractCheck::checkFileInternal()
  *
  * @param \HippoPHP\Hippo\CheckContext  $checkContext
  * @param \HippoPHP\Hippo\Config\Config $config
  */
 protected function checkFileInternal(CheckContext $checkContext, Config $config)
 {
     $file = $checkContext->getFile();
     $this->setIndentStyle($config->get('style', $this->indentStyle));
     $this->setIndentCount($config->get('count', $this->indentCount));
     $indentation = $this->getBaseIndentation();
     $lines = $this->getLines($checkContext->getTokenList());
     $level = 0;
     foreach ($lines as $lineNumber => $line) {
         $actualIndentation = '';
         if (count($line) > 0) {
             if ($line[0]->isType(T_WHITESPACE)) {
                 $actualIndentation = $line[0]->getContent();
             }
         }
         foreach ($line as $token) {
             $content = $token->getContent();
             if ($content === '}' || $content === ')' || $content === ']') {
                 $level--;
             }
         }
         $expectedIndentation = $level > 0 ? str_repeat($indentation, $level) : '';
         if ($expectedIndentation !== $actualIndentation) {
             $this->addViolation($file, $lineNumber, count($line) > 0 ? $line[0]->getColumn() + strlen($line[0]->getContent()) : 1, sprintf('Unexpected indentation (expected: %s, actual: %s)', $this->escape($expectedIndentation), $this->escape($actualIndentation)), Violation::SEVERITY_WARNING);
         }
         foreach ($line as $token) {
             $content = $token->getContent();
             if ($content === '{' || $content === '(' || $content === '[') {
                 $level++;
             }
         }
     }
 }
All Usage Examples Of HippoPHP\Hippo\Config\Config::get