Skip to content

Commit

Permalink
- Added Exception for Redeclaration of classes
Browse files Browse the repository at this point in the history
- Enhanced the --indent option to interpet nummeric values as space count
- Refactor parseFile to not need a local array, saves pointless array_merge
- Bump Copyright to 2011
  • Loading branch information
theseer committed Jan 9, 2011
1 parent 640e294 commit ffd2e8d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
6 changes: 3 additions & 3 deletions phpab.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -51,8 +51,8 @@
require __DIR__ . '/src/staticbuilder.php';
require __DIR__ . '/src/dependencysorter.php';

require __DIR__ . '/src/autoloadbuildercli.php';
require __DIR__ . '/src/cli.php';

$exec = new \TheSeer\Tools\AutoloadBuilderCLI();
$exec = new \TheSeer\Tools\CLI();
$exec->run();
exit(0);
2 changes: 1 addition & 1 deletion src/autoloadbuilder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down
20 changes: 15 additions & 5 deletions src/classfinder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getDependencies() {
* @return integer
*/
public function parseFile($file) {
$entries = array();
$entries = 0;
$classFound = false;
$nsFound = false;
$nsProc = false;
Expand Down Expand Up @@ -182,7 +182,17 @@ public function parseFile($file) {
$nsFound = false;
} elseif ($classFound) {
$lastClass = ($inNamespace ? $inNamespace .'\\\\' : '') . strtolower($tok[1]);
$entries[$lastClass] = $file;
if (isset($this->foundClasses[$lastClass])) {
throw new ClassFinderException(sprintf(
"Redeclaration of class '%s' detected\n Original: %s\n Secondary: %s\n\n",
$lastClass,
$this->foundClasses[$lastClass],
$file
), ClassFinderException::ClassRedeclaration
);
}
$this->foundClasses[$lastClass] = $file;
$entries++;
$classFound = false;
} elseif ($extendsFound || $implementsFound) {
if ($classNameStart && $inNamespace) {
Expand All @@ -196,8 +206,7 @@ public function parseFile($file) {
}
}

$this->foundClasses = array_merge($this->foundClasses, $entries);
return count($entries);
return $entries;
}

/**
Expand All @@ -221,6 +230,7 @@ public function parseMulti(\Iterator $sources) {
class ClassFinderException extends \Exception {

const NoDependencies = 1;
const ClassRedeclaration = 2;

}
}
16 changes: 10 additions & 6 deletions src/autoloadbuildercli.php → src/cli.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -44,7 +44,7 @@
* @author Arne Blankerts <arne@blankerts.de>
* @copyright Arne Blankerts <arne@blankerts.de>, All rights reserved.
*/
class AutoloadBuilderCLI {
class CLI {

/**
* Version identifier
Expand Down Expand Up @@ -297,7 +297,11 @@ protected function getBuilder(ClassFinder $finder, \ezcConsoleInput $input) {

$indent = $input->getOption('indent');
if ($indent->value) {
$ab->setIndent($indent->value);
if (is_numeric($indent->value)) {
$ab->setIndent(str_repeat(' ', $indent->value));
} else {
$ab->setIndent($indent->value);
}
} elseif ($isStatic) {
$ab->setIndent('');
}
Expand Down Expand Up @@ -386,7 +390,7 @@ protected function lintCode($code, $input) {
* Helper to output version information
*/
protected function showVersion() {
printf("phpab %s - Copyright (C) 2009 - 2010 by Arne Blankerts\n\n", self::VERSION);
printf("phpab %s - Copyright (C) 2009 - 2011 by Arne Blankerts\n\n", self::VERSION);
}

/**
Expand All @@ -409,8 +413,8 @@ protected function showUsage() {
-s, --static Generate a static require file
--format Dateformat string for timestamp
--linebreak Linebreak style (CR, CR/LF or LF)
--indent String used for indenting (default: 3 spaces)
--linebreak Linebreak style (CR, CRLF or LF, default: LF)
--indent String used for indenting or number of spaces (default: 12 spaces)
--lint Run lint on generated code and exit
--lint-php PHP binary to use for linting (default: /usr/bin/php or c:\php\php.exe)
Expand Down
2 changes: 1 addition & 1 deletion src/dependencysorter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion src/staticbuilder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2009-2010 Arne Blankerts <arne@blankerts.de>
* Copyright (c) 2009-2011 Arne Blankerts <arne@blankerts.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down

0 comments on commit ffd2e8d

Please sign in to comment.