Skip to content

Commit

Permalink
Version 0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
clbustos committed Jun 6, 2006
1 parent dc282dc commit 0c45853
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 37 deletions.
15 changes: 8 additions & 7 deletions Beautifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ public function __construct()
T_DO=>'T_CONTROL',
T_WHILE=>'T_CONTROL',
T_SWITCH=>'T_CONTROL',
T_CASE=>'T_CONTROL',
/* ELSE */
T_ELSEIF=>'T_ELSE',
T_ELSE=>'T_ELSE',
Expand Down Expand Up @@ -844,13 +843,15 @@ private function controlToken($aCurrentToken)
break;

case '{':
if ($this->getPreviousTokenConstant() == T_VARIABLE or ($this->getPreviousTokenConstant() == T_STRING and $this->getPreviousTokenConstant(2) == T_OBJECT_OPERATOR)) {
if ($this->isPreviousTokenConstant(T_VARIABLE) or ($this->isPreviousTokenConstant(T_STRING) and $this->getPreviousTokenConstant(2) == T_OBJECT_OPERATOR)
or $this->isPreviousTokenConstant(T_OBJECT_OPERATOR)
) {
$this->setMode('string_index');
}
break;

case '}':
$this->oLog->log('end bracket:'.$this->getPreviousTokenContent() ."\n");
$this->oLog->log('end bracket:'.$this->getPreviousTokenContent(),PEAR_LOG_DEBUG);
if ($this->getPreviousTokenContent() == ';' or $this->getPreviousTokenContent() == '}' or $this->getPreviousTokenContent() == '{') {
$this->popControlSeq();
}
Expand Down Expand Up @@ -935,7 +936,7 @@ private function controlTokenPost($aCurrentToken)
*/
private function pushControlSeq($aToken)
{
$this->oLog->log('Push:'.$aToken[0]."->".$aToken[1]);
$this->oLog->log('Push:'.$aToken[0]."->".$aToken[1],PEAR_LOG_DEBUG);
array_push($this->aControlSeq, $aToken[0]);
}
/**
Expand All @@ -945,7 +946,7 @@ private function pushControlSeq($aToken)
private function popControlSeq()
{
$aEl = array_pop($this->aControlSeq);
$this->oLog->log('Pop:'.$aEl);
$this->oLog->log('Pop:'.$aEl,PEAR_LOG_DEBUG);
return $aEl;
}
/**
Expand All @@ -954,7 +955,7 @@ private function popControlSeq()
private function pushControlParenthesis()
{
$iPrevious = $this->getPreviousTokenConstant();
$this->oLog->log("Push Parenthesis: $iPrevious ->".$this->getPreviousTokenContent());
$this->oLog->log("Push Parenthesis: $iPrevious ->".$this->getPreviousTokenContent(),PEAR_LOG_DEBUG);
array_push($this->aControlParenthesis, $iPrevious);
}
/**
Expand All @@ -964,7 +965,7 @@ private function pushControlParenthesis()
private function popControlParenthesis()
{
$iPop = array_pop($this->aControlParenthesis);
$this->oLog->log('Pop Parenthesis:'.$iPop);
$this->oLog->log('Pop Parenthesis:'.$iPop,PEAR_LOG_DEBUG);
return $iPop;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion Beautifier/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function handleToken($token)
return ($this->$sMethod($sValue) !== PHP_Beautifier_Filter::BYPASS);
} else { // WEIRD!!! -> Add the same received
$this->oBeaut->add($token[1]);
PHP_Beautifier_Common::getLog()->log("Add same received:".trim($token[1]));
PHP_Beautifier_Common::getLog()->log("Add same received:".trim($token[1]), PEAR_LOG_DEBUG);
return true;
}
// never go here
Expand Down
3 changes: 3 additions & 0 deletions Beautifier/Filter/Default.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function t_control($sTag)
{
$this->oBeaut->add($sTag.' ');
}
function t_case($sTag) {
$this->oBeaut->add($sTag.' ');
}
function t_parenthesis_open($sTag)
{
$this->oBeaut->add($sTag);
Expand Down
2 changes: 1 addition & 1 deletion Beautifier/Filter/Lowercase.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __call($sMethod, $aArgs)
$iToken = $this->aToken[0];
$sContent = $this->aToken[1];
if(in_array($iToken,$this->aControlSeq)) {
$this->oLog->log("Lowercase:".$sContent);
$this->oLog->log("Lowercase:".$sContent, PEAR_LOG_DEBUG);
$this->oBeaut->add(" ".strtolower($sContent)." ");
} else {
return PHP_Beautifier_Filter::BYPASS;
Expand Down
4 changes: 2 additions & 2 deletions Doc_PHP_Beautifier.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ readmeinstallchangelog = README, INSTALL, CHANGELOG, NEWS, FAQ, LICENSE

;; comma-separated list of files to parse
;; legal values: paths separated by commas
filename = /usr/local/php5/lib/php/PHP/Beautifier.php
filename = /usr/share/php/PHP/Beautifier.php

;; comma-separated list of directories to parse
;; legal values: directory paths separated by commas
;directory = /path1,/path2,.,..,subdirectory
;directory = /home/jeichorn/cvs/pear
directory = /usr/local/php5/lib/php/PHP/Beautifier,/home/cdx/www/PHP_Beautifier/tutorials
directory = /usr/share/php/PHP/Beautifier,/home/cdx/www/PHP_Beautifier/tutorials

;; template base directory (the equivalent directory of <installdir>/phpDocumentor)
;templatebase = /path/to/my/templates
Expand Down
3 changes: 2 additions & 1 deletion examples/example_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class class_1 extends class_0 {
}
switch ($b) {
case 'a':
echo 'a';
case 'b':
echo 'a';
echo 'b';
break;

default:
Expand Down
33 changes: 20 additions & 13 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
</maintainers>

<release>
<version>0.1.9</version>
<date>2006-06-05</date>
<notes>¡The one before stable!
- Bug fix[Internal 2]: Code to detect default token constant was wrong. This solve strange extra white lines on output.
- Bug fix[#7305]: add spaces before and after array key-value pair assignator (=>)
- Bug fix[#7307]: first lines are intended if ListClassFunction is enabled
- Bug fix[#7308]: typo in "How to use PHP_Beautifier": 'standar' should be 'standard'
- Bug fix[#7312]: missing spaces with lower and greater than operator. missing spaces with after ; in for statemants
- Bug fix[#7759]: Adding a comment after a case statement in a switch causes the
indenting to be wrong.
+ New Lowercase Filter[requested on #7348]: Lowercase all control structures. Parse the output of this filter with a new instance of the object or with a pipe in a new php_beautifier.

<version>0.1.10</version>
<date>2006-06-06</date>
<notes>The one NOT before stable: ( The day of the AC!
- Bug fix[7818]: Where curly brackets are used to indicate a variable class
property, PHP_Beautifier adds extra whitespace as if it were
parsing a class method or function.
- Internal Bug 3: Removed log messages on command line. Use -v to get the verbose output (messages with PEAR_DEBUG_INFO level).
! Bug 7759 remains open, only when one or more case doesn't ends with a break.
</notes>
<state>beta</state>
<filelist>
Expand Down Expand Up @@ -176,10 +172,21 @@ indenting to be wrong.
<dep type="ext" rel="has" optional="yes" version="0">bz2</dep>
</deps>
<changelog>
<release>
<version>0.1.10</version>
<date>2006-06-06</date>
<notes>The one NOT before stable: ( The day of the AC!
- Bug fix[7818]: Where curly brackets are used to indicate a variable class
property, PHP_Beautifier adds extra whitespace as if it were
parsing a class method or function.
- Internal Bug 3: Removed log messages on command line. Use -v to get the verbose output (messages with PEAR_DEBUG_INFO level).
! Bug 7759 remains open, only when one or more case doesn't ends with a break.
</notes>
</release>
<release>
<version>0.1.9</version>
<date>2006-06-05</date>
<notes>¡The one before stable!
<notes>The one before stable!
- Bug fix[Internal 2]: Code to detect default token constant was wrong. This solve strange extra white lines on output.
- Bug fix[#7305]: add spaces before and after array key-value pair assignator (=>)
- Bug fix[#7307]: first lines are intended if ListClassFunction is enabled
Expand Down
26 changes: 17 additions & 9 deletions scripts/php_beautifier
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@
error_reporting(E_ALL);
// get log object
$oLog = PHP_Beautifier_Common::getLog();
// add the console logger
$oLogConsole = Log::factory('console', '', 'php_beautifier', array(
'stream'=>STDERR
) , PEAR_LOG_INFO);
$oLog->addChild($oLogConsole);

//default_options
$aInputFiles = STDIN;
$sOutputFile = STDOUT;
Expand All @@ -69,6 +65,7 @@
$bRecursive = false;
$sCompress = false;
$aFiltersDirectory = array();
$iVerbose=PEAR_LOG_WARNING;
//end default_options
$argv = Console_Getopt::readPHPArgv();
$aLongOptions = array(
Expand All @@ -80,9 +77,10 @@
'directory_filters=',
'recursive',
'help',
'compress=='
'compress==',
'verbose'
);
$options = Console_Getopt::getopt($argv, "f:o:d:l:t::s::c::r?", $aLongOptions);
$options = Console_Getopt::getopt($argv, "f:o:d:l:t::s::c::r?v", $aLongOptions);
if (PEAR::isError($options)) {
usage($options);
}
Expand Down Expand Up @@ -155,8 +153,18 @@
case '?':
usage();
break;
case 'v':
case 'verbose':
$iVerbose=PEAR_LOG_INFO;
break;
}
}
// add the console logger
$oLogConsole = Log::factory('console', '', 'php_beautifier', array(
'stream'=>STDERR
) , $iVerbose);
$oLog->addChild($oLogConsole);

if (!empty($options[1])) {
$aFiles = $options[1];
if (count($options[1]) == 1) {
Expand All @@ -170,8 +178,8 @@
$sOutputFile = ($sOut == '-') ? STDOUT : $sOut;
}
}
$oLog->log("In :".@implode(',', $aInputFiles) , PEAR_LOG_DEBUG);
$oLog->log("Out:".$sOutputFile, PEAR_LOG_DEBUG);
$oLog->log("In :".@implode(',', $aInputFiles) , PEAR_LOG_INFO);
$oLog->log("Out:".$sOutputFile, PEAR_LOG_INFO);
$start = time();
ini_set('max_execution_time', 0);
// start script
Expand Down
5 changes: 2 additions & 3 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
error_reporting(E_ALL|E_STRICT);
require_once ('./Beautifier.php');
$oBeaut = new PHP_Beautifier();
$oBeaut->startLog();
$oBeaut->addFilter('Lowercase');
$oBeaut->setInputFile('examples/example_lowercase.php');
//$oBeaut->startLog();
$oBeaut->setInputFile('examples/example_main.php');
$oBeaut->process();
$oBeaut->show();
?>
20 changes: 20 additions & 0 deletions tests/Beautifier_Bugs.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ case 5:
echo 1;
break;
case 2: //2
echo "something";
echo "something";
case 3: /*3 */ /* 3? */
case 4: //3
default:
Expand All @@ -366,6 +368,8 @@ switch (1) {
echo 1;
break;
case 2: //2
echo "something";
echo "something";
case 3: /*3 */ /* 3? */
case 4: //3
default:
Expand All @@ -377,6 +381,22 @@ echo 1;
SCRIPT;
$this->assertEquals($sExpected, $this->oBeaut->get());
}
function test7818() {
$this->oBeaut->startLog();
$sText=<<<SCRIPT
<?php
\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
?>
SCRIPT;
$this->setText($sText);

$sExpected = <<<SCRIPT
<?php
\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
?>
SCRIPT;
$this->assertEquals($sExpected, $this->oBeaut->get());
}
}
$suite = new PHPUnit_TestSuite('Beautifier_Bugs');
$result = PHPUnit::run($suite);
Expand Down

0 comments on commit 0c45853

Please sign in to comment.