Skip to content

Commit

Permalink
Indenting cleanup 3 -> 4 spaces, a first phpcs.xml to support code sn…
Browse files Browse the repository at this point in the history
…iffer
  • Loading branch information
theseer committed Apr 3, 2011
1 parent 551f2aa commit 6e3f803
Show file tree
Hide file tree
Showing 19 changed files with 1,075 additions and 1,034 deletions.
40 changes: 40 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<ruleset name="Arne">
<description>Arne Blankerts' coding standard</description>

<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>

<rule ref="Generic.Commenting.Todo"/>

<rule ref="Generic.ControlStructures.InlineControlStructure"/>

<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>

<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>

<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
<rule ref="Generic.Functions.FunctionCallArgumentSpacing" />
<rule ref="PEAR.Functions.ValidDefaultValue"/>

<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="PEAR.NamingConventions.ValidClassName"/>

<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.NoSilencedErrors"/>

<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>

<!-- Namespace handling broken, so disabled -->
<!--<rule ref="Generic.WhiteSpace.ScopeIndent"/>-->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
</ruleset>
300 changes: 150 additions & 150 deletions src/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,174 +37,174 @@
*/
namespace TheSeer\phpDox {

use \TheSeer\fDom\fDomDocument;

class Application {

/**
* Logger for progress and error reporting
*
* @var Logger
*/
protected $logger;

/**
* Base path xml files are stored in
*
* @var string
*/
protected $xmlDir;

/**
* Array of Container DOM Documents
*
* @var array
*/
protected $container = array();

/**
* Constructor of PHPDox Application
*
* @param ProgressLogger $logger Instance of the ProgressLogger class
* @param string $xmlDir Directory where (generated) xml files are stored in
*/
public function __construct(ProgressLogger $logger, $xmlDir) {
$this->logger = $logger;
$this->xmlDir = $xmlDir;
}

/**
* Run collection process on given directory tree
*
* @param string $srcDir Base path of source tree
* @param DirectoryScanner $scanner A Directory scanner object to process
* @param boolean $publicOnly Flag to enable processing of only public methods and members
*
* @return void
*/
public function runCollector($srcDir, $scanner, $publicOnly = false) {
$collector = new Collector(
use \TheSeer\fDom\fDomDocument;

class Application {

/**
* Logger for progress and error reporting
*
* @var Logger
*/
protected $logger;

/**
* Base path xml files are stored in
*
* @var string
*/
protected $xmlDir;

/**
* Array of Container DOM Documents
*
* @var array
*/
protected $container = array();

/**
* Constructor of PHPDox Application
*
* @param ProgressLogger $logger Instance of the ProgressLogger class
* @param string $xmlDir Directory where (generated) xml files are stored in
*/
public function __construct(ProgressLogger $logger, $xmlDir) {
$this->logger = $logger;
$this->xmlDir = $xmlDir;
}

/**
* Run collection process on given directory tree
*
* @param string $srcDir Base path of source tree
* @param DirectoryScanner $scanner A Directory scanner object to process
* @param boolean $publicOnly Flag to enable processing of only public methods and members
*
* @return void
*/
public function runCollector($srcDir, $scanner, $publicOnly = false) {
$collector = new Collector(
$this->xmlDir,
$this->getContainerDocument('namespaces'),
$this->getContainerDocument('interfaces'),
$this->getContainerDocument('classes')
);
$collector->setPublicOnly($publicOnly);
$collector->run($scanner, $this->logger);
$this->cleanUp($srcDir);
$this->saveContainer();
}

/**
* Run Documentation generation process
*
* @param string $backend Name of the backend to use for generation
* @param string $docDir Output directory to store documentation in
* @param boolean $publicOnly Flag to enable processing of only public methods and members
*
* @return void
*/
public function runGenerator($backend, $docDir, $publicOnly = false) {
$generator = new Generator(
);
$collector->setPublicOnly($publicOnly);
$collector->run($scanner, $this->logger);
$this->cleanUp($srcDir);
$this->saveContainer();
}

/**
* Run Documentation generation process
*
* @param string $backend Name of the backend to use for generation
* @param string $docDir Output directory to store documentation in
* @param boolean $publicOnly Flag to enable processing of only public methods and members
*
* @return void
*/
public function runGenerator($backend, $docDir, $publicOnly = false) {
$generator = new Generator(
$this->xmlDir,
$docDir,
$this->getContainerDocument('namespaces'),
$this->getContainerDocument('interfaces'),
$this->getContainerDocument('classes')
);
$generator->setPublicOnly($publicOnly);
$generator->run($backend);
}

/**
* Helper to load or create Container DOM Documents for namespaces, classes, interfaces, ...
*
* @param string $name name of the file (identical to root node)
*
* @return \TheSeer\fDom\fDomDocument
*/
protected function getContainerDocument($name) {
$fname = $this->xmlDir . '/' . $name .'.xml';
if (isset($this->container[$fname])) {
return $this->container[$fname];
}
$dom = new fDOMDocument('1.0', 'UTF-8');
if (file_exists($fname)) {
$dom->load($fname);
} else {
$rootNode = $dom->createElementNS('http://phpdox.de/xml#', $name);
$dom->appendChild($rootNode);
}
$dom->registerNamespace('phpdox', 'http://phpdox.de/xml#');
$dom->formatOutput = true;
$this->container[$fname] = $dom;
return $dom;
}

/**
* Helper to save all known and (updated) container files.
*/
protected function saveContainer() {
foreach($this->container as $fname => $dom) {
$dom->save($fname);
}
}

/**
* Helper to cleanup
*
* @param string $srcDir Source directory to compare xml structure with
*/
protected function cleanup($srcDir) {
$worker = new \RecursiveIteratorIterator(
);
$generator->setPublicOnly($publicOnly);
$generator->run($backend);
}

/**
* Helper to load or create Container DOM Documents for namespaces, classes, interfaces, ...
*
* @param string $name name of the file (identical to root node)
*
* @return \TheSeer\fDom\fDomDocument
*/
protected function getContainerDocument($name) {
$fname = $this->xmlDir . '/' . $name .'.xml';
if (isset($this->container[$fname])) {
return $this->container[$fname];
}
$dom = new fDOMDocument('1.0', 'UTF-8');
if (file_exists($fname)) {
$dom->load($fname);
} else {
$rootNode = $dom->createElementNS('http://xml.phpdox.de/src#', $name);
$dom->appendChild($rootNode);
}
$dom->registerNamespace('phpdox', 'http://xml.phpdox.de/src#');
$dom->formatOutput = true;
$this->container[$fname] = $dom;
return $dom;
}

/**
* Helper to save all known and (updated) container files.
*/
protected function saveContainer() {
foreach($this->container as $fname => $dom) {
$dom->save($fname);
}
}

/**
* Helper to cleanup
*
* @param string $srcDir Source directory to compare xml structure with
*/
protected function cleanup($srcDir) {
$worker = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->xmlDir, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
$len = strlen($this->xmlDir);
$srcPath = realpath($srcDir);

if (strpos($srcDir, $srcPath) === 0) {
$srcPath = '/';
}
else {
$srcPath = dirname($srcPath) . '/';
}

$containers = array(
);
$len = strlen($this->xmlDir);
$srcPath = realpath($srcDir);

if (strpos($srcDir, $srcPath) === 0) {
$srcPath = '/';
}
else {
$srcPath = dirname($srcPath) . '/';
}

$containers = array(
$this->getContainerDocument('namespaces'),
$this->getContainerDocument('classes'),
$this->getContainerDocument('interfaces')
);
);

$whitelist = array(
$whitelist = array(
$this->xmlDir . '/namespaces.xml',
$this->xmlDir . '/classes.xml',
$this->xmlDir . '/interfaces.xml'
);

foreach($worker as $fname => $file) {
$fname = $file->getPathname();
if (in_array($fname, $whitelist)) {
continue;
}
if ($file->isFile()) {
$srcFile = $srcPath . substr($fname,$len+1,-4);
if (!file_exists($srcFile)) {
unlink($fname);
foreach($containers as $dom) {
foreach($dom->query("//phpdox:*[@src='{$srcFile}']") as $node) {
$node->parentNode->removeChild($node);
}
}
}
} elseif ($file->isDir()) {
$srcDir = $srcPath . substr($file->getPathname(),$len+1);
if (!file_exists($srcDir)) {
rmdir($fname);
}
);

foreach($worker as $fname => $file) {
$fname = $file->getPathname();
if (in_array($fname, $whitelist)) {
continue;
}
if ($file->isFile()) {
$srcFile = $srcPath . substr($fname, $len+1, -4);
if (!file_exists($srcFile)) {
unlink($fname);
foreach($containers as $dom) {
foreach($dom->query("//phpdox:*[@src='{$srcFile}']") as $node) {
$node->parentNode->removeChild($node);
}
}
}
} elseif ($file->isDir()) {
$srcDir = $srcPath . substr($file->getPathname(), $len+1);
if (!file_exists($srcDir)) {
rmdir($fname);
}
}
}
}
}
}

}
}
}
Loading

0 comments on commit 6e3f803

Please sign in to comment.