getCode() public method

public getCode ( ) : string
return string
Example #1
0
 public function testAddStatement()
 {
     $code = new Code();
     $code->addStatement('$a = 10;');
     $this->assertSame('$a = 10;', $code->getCode());
     $code->addStatement('return $a;');
     $this->assertSame("\$a = 10;\nreturn \$a;", $code->getCode());
 }
Example #2
0
 /**
  * @param  Code   $code
  * @throws \RuntimeException
  * @return mixed
  */
 public function run(Code $code)
 {
     $this->logger->debug(sprintf('Executing code: %s', $code->getCode()));
     $data = $this->doRun($code);
     $result = @unserialize($data);
     if (!is_array($result)) {
         $this->logger->debug(sprintf('Return serialized: %s', $data));
         throw new \RuntimeException('Could not unserialize data from adapter.');
     }
     $this->logger->debug(sprintf('Return errors: %s', json_encode($result['errors'])));
     $this->logger->debug(sprintf('Return result: %s', json_encode($result['result'])));
     if (empty($result['errors'])) {
         return $result['result'];
     }
     $errors = array_reduce($result['errors'], function ($carry, $error) {
         return $carry .= "{$error['str']} (error code: {$error['no']})\n";
     });
     throw new \RuntimeException($errors);
 }