/** * @param Scalar\LNumber $lNum * @param Context $context * @return bool */ public function pass(Scalar\LNumber $lNum, Context $context) { if ($lNum->getAttribute('kind') != Scalar\LNumber::KIND_DEC) { $context->notice('l_number_kind', 'Avoid using octal, hexadecimal or binary', $lNum); return true; } return false; }
protected function reduceRule322() { $this->semValue = new Scalar\LNumber(Scalar\LNumber::parse($this->semStack[$this->stackPos - (1 - 1)]), $this->startAttributeStack[$this->stackPos - (1 - 1)] + $this->endAttributes); }
public function pScalar_LNumber(Scalar\LNumber $node) { $str = (string) $node->value; switch ($node->getAttribute('kind', Scalar\LNumber::KIND_DEC)) { case Scalar\LNumber::KIND_BIN: return '0b' . base_convert($str, 10, 2); case Scalar\LNumber::KIND_OCT: return '0' . base_convert($str, 10, 8); case Scalar\LNumber::KIND_DEC: return $str; case Scalar\LNumber::KIND_HEX: return '0x' . base_convert($str, 10, 16); } throw new \Exception('Invalid number kind'); }
protected function reduceRule397() { $this->semValue = Scalar\LNumber::fromString($this->semStack[$this->stackPos - (1 - 1)], $this->startAttributeStack[$this->stackPos - (1 - 1)] + $this->endAttributes); }
protected function parseLNumber($str, $attributes, $allowInvalidOctal = false) { try { return LNumber::fromString($str, $attributes, $allowInvalidOctal); } catch (Error $error) { $this->emitError($error); // Use dummy value return new LNumber(0, $attributes); } }
protected function reduceRule323($attributes) { $this->semValue = new Node\Scalar\LNumber(Node\Scalar\LNumber::parse($this->semStack[$this->stackPos - (1 - 1)]), $attributes); }
public function provideTestParse() { return [['<?php class Test { function function() {} }', $this->getPrefer5(), [new Stmt\Class_('Test', ['stmts' => [new Stmt\ClassMethod('function')]])]], ['<?php global $$a->b;', $this->getPrefer7(), [new Stmt\Global_([new Expr\Variable(new Expr\PropertyFetch(new Expr\Variable('a'), 'b'))])]], ['<?php $$a[0];', $this->getPrefer5(), [new Expr\Variable(new Expr\ArrayDimFetch(new Expr\Variable('a'), LNumber::fromString('0')))]], ['<?php $$a[0];', $this->getPrefer7(), [new Expr\ArrayDimFetch(new Expr\Variable(new Expr\Variable('a')), LNumber::fromString('0'))]]]; }
protected function pScalar_LNumber(Scalar\LNumber $node) { if ($node->value === -\PHP_INT_MAX-1) { // PHP_INT_MIN cannot be represented as a literal, // because the sign is not part of the literal return '(-' . \PHP_INT_MAX . '-1)'; } $kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC); if (Scalar\LNumber::KIND_DEC === $kind) { return (string) $node->value; } $sign = $node->value < 0 ? '-' : ''; $str = (string) $node->value; switch ($kind) { case Scalar\LNumber::KIND_BIN: return $sign . '0b' . base_convert($str, 10, 2); case Scalar\LNumber::KIND_OCT: return $sign . '0' . base_convert($str, 10, 8); case Scalar\LNumber::KIND_HEX: return $sign . '0x' . base_convert($str, 10, 16); } throw new \Exception('Invalid number kind'); }