public function __toString() { $string = ''; if (sizeof($this->coverage) > 0) { try { $nodes = array('coverage' => round($this->coverage->getValue() * 100, 2), 'project' => $this->projectName, 'name' => '', 'fullname' => '', 'htmlReportBaseUrl' => $this->htmlReportBaseUrl, 'date' => time(), 'children' => array()); foreach ($this->coverage->getClasses() as $className => $classPath) { $node =& $nodes; $class = new \reflectionClass($className); $namespaces = explode('\\', $class->getNamespaceName()); foreach ($namespaces as $namespace) { $childFound = false; foreach ($node['children'] as $key => $child) { $childFound = $child['name'] === $namespace; if ($childFound === true) { break; } } if ($childFound === false) { $key = sizeof($node['children']); $node['children'][] = array('name' => $namespace, 'fullname' => $node['fullname'] . ($node['fullname'] == '' ? '' : '\\') . $namespace, 'children' => array()); } $node =& $node['children'][$key]; } $child = array('name' => $class->getShortName(), 'fullname' => $node['fullname'] . '\\' . $class->getShortName(), 'covered' => $this->coverage->getNumberOfCoveredLinesInClass($className), 'coverable' => $this->coverage->getNumberOfCoverableLinesInClass($className), 'pourcent' => round($this->coverage->getValueForClass($className) * 100, 2), 'children' => array()); $node['children'][] = $child; } if (@file_put_contents($this->destinationDirectory . DIRECTORY_SEPARATOR . self::dataFile, json_encode($nodes)) === false) { throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\'')); } try { $resourcesDirectoryIterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\dot($this->resourcesDirectory)); } catch (\exception $exception) { throw new exceptions\runtime($this->locale->_('Directory \'' . $this->resourcesDirectory . '\' does not exist')); } foreach ($resourcesDirectoryIterator as $file) { if (@copy($file, $this->destinationDirectory . DIRECTORY_SEPARATOR . $resourcesDirectoryIterator->getSubPathname()) === false) { throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\'')); } } $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Treemap of code coverage are available at %s.'), $this->treemapUrl)) . PHP_EOL; } catch (\exception $exception) { $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Unable to generate code coverage at %s: %s.'), $this->treemapUrl, $exception->getMessage())) . PHP_EOL; } } return $string; }
private function addToPool($entity) { $reflection = new reflectionClass($entity); $class = $reflection->getShortName(); if (!$this->collectionExist($class)) { static::$pool[$class] = new Collection(); } static::$pool[$class]->push($entity->id); return $entity; }