Skip to content

Commit

Permalink
Replace copy-pasted class names with self and __CLASS__
Browse files Browse the repository at this point in the history
I find this best practice. It makes it much easier to work with and
e.g. possibly rename classes. It also makes it easier to search for a
class name and find usages, without the search results being poluted
by self-references.

Change-Id: If08a0a247ac4cd771ffce5354340b2b8d70cb136
  • Loading branch information
thiemowmde authored and Krinkle committed Aug 30, 2023
1 parent 1c4f668 commit 06ab7ce
Show file tree
Hide file tree
Showing 31 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions lib/Less/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function register() {
return;
}

if ( !spl_autoload_register( [ 'Less_Autoloader', 'loadClass' ] ) ) {
if ( !spl_autoload_register( [ __CLASS__, 'loadClass' ] ) ) {
throw new Exception( 'Unable to register Less_Autoloader::loadClass as an autoloading method.' );
}

Expand All @@ -32,7 +32,7 @@ public static function register() {
* @return void
*/
public static function unregister() {
spl_autoload_unregister( [ 'Less_Autoloader', 'loadClass' ] );
spl_autoload_unregister( [ __CLASS__, 'loadClass' ] );
self::$registered = false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function Init() {
}

public function copyEvalEnv( $frames = [] ) {
$new_env = new Less_Environment();
$new_env = new self();
$new_env->frames = $frames;
return $new_env;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function rgb( $r = null, $g = null, $b = null ) {

public function rgba( $r = null, $g = null, $b = null, $a = null ) {
$rgb = [ $r, $g, $b ];
$rgb = array_map( [ 'Less_Functions','scaled' ], $rgb );
$rgb = array_map( [ __CLASS__, 'scaled' ], $rgb );

$a = self::number( $a );
return new Less_Tree_Color( $rgb, $a );
Expand Down
6 changes: 3 additions & 3 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private function PostVisitors( $evaldRoot ) {
* @throws Less_Exception_Parser If the compiler encounters invalid syntax
* @param string $str The string to convert
* @param string|null $file_uri The url of the file
* @return Less_Parser
* @return $this
*/
public function parse( $str, $file_uri = null ) {
if ( !$file_uri ) {
Expand Down Expand Up @@ -427,7 +427,7 @@ public function parse( $str, $file_uri = null ) {
* @param string $filename The file to parse
* @param string $uri_root The url of the file
* @param bool $returnRoot Indicates whether the return value should be a css string a root node
* @return Less_Tree_Ruleset|Less_Parser
* @return Less_Tree_Ruleset|$this
*/
public function parseFile( $filename, $uri_root = '', $returnRoot = false ) {
if ( !file_exists( $filename ) ) {
Expand Down Expand Up @@ -469,7 +469,7 @@ public function parseFile( $filename, $uri_root = '', $returnRoot = false ) {
/**
* Allows a user to set variables values
* @param array $vars
* @return Less_Parser
* @return $this
*/
public function ModifyVars( $vars ) {
$this->input = self::serializeVars( $vars );
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct( $value, $index = null, $currentFileInfo = null, $ma
}

public function compile( $env ) {
return new Less_Tree_Anonymous( $this->value, $this->index, $this->currentFileInfo, $this->mapLines );
return new self( $this->value, $this->index, $this->currentFileInfo, $this->mapLines );
}

public function compare( $x ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function accept( $visitor ) {
}

public function compile( $env ) {
return new Less_Tree_Assignment( $this->key, $this->value->compile( $env ) );
return new self( $this->key, $this->value->compile( $env ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function compile( $env ) {
return $this;
}

return new Less_Tree_Attribute(
return new self(
$key_obj ? $this->key->compile( $env ) : $this->key,
$this->op,
$val_obj ? $this->value->compile( $env ) : $this->value );
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function compile( $env = null ) {
return $result;
}

return new Less_Tree_Call( $this->name, $args, $this->index, $this->currentFileInfo );
return new self( $this->name, $args, $this->index, $this->currentFileInfo );
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Less/Tree/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function toCSS( $doNotCompress = false ) {

/**
* @param string $op
* @param Less_Tree_Color $other
* @param self $other
*/
public function operate( $op, $other ) {
$rgb = [];
$alpha = $this->alpha * ( 1 - $other->alpha ) + $other->alpha;
for ( $c = 0; $c < 3; $c++ ) {
$rgb[$c] = Less_Functions::operate( $op, $this->rgb[$c], $other->rgb[$c] );
}
return new Less_Tree_Color( $rgb, $alpha );
return new self( $rgb, $alpha );
}

public function toRGB() {
Expand Down Expand Up @@ -217,11 +217,11 @@ public static function fromKeyword( $keyword ) {

if ( Less_Colors::hasOwnProperty( $keyword ) ) {
// detect named color
return new Less_Tree_Color( substr( Less_Colors::color( $keyword ), 1 ) );
return new self( substr( Less_Colors::color( $keyword ), 1 ) );
}

if ( $keyword === 'transparent' ) {
return new Less_Tree_Color( [ 0, 0, 0 ], 0, true );
return new self( [ 0, 0, 0 ], 0, true );
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/DetachedRuleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function compile( $env ) {
} else {
$frames = $env->frames;
}
return new Less_Tree_DetachedRuleset( $this->ruleset, $frames );
return new self( $this->ruleset, $frames );
}

public function callEval( $env ) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Less/Tree/Dimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __toString() {

/**
* @param string $op
* @param Less_Tree_Dimension $other
* @param self $other
*/
public function operate( $op, $other ) {
$value = Less_Functions::operate( $op, $this->value, $other->value );
Expand Down Expand Up @@ -106,11 +106,11 @@ public function operate( $op, $other ) {
sort( $unit->denominator );
$unit->cancel();
}
return new Less_Tree_Dimension( $value, $unit );
return new self( $value, $unit );
}

public function compare( $other ) {
if ( $other instanceof Less_Tree_Dimension ) {
if ( $other instanceof self ) {

if ( $this->unit->isEmpty() || $other->unit->isEmpty() ) {
$a = $this;
Expand Down Expand Up @@ -185,6 +185,6 @@ public function convertTo( $conversions ) {

$unit->cancel();

return new Less_Tree_Dimension( $value, $unit );
return new self( $value, $unit );
}
}
2 changes: 1 addition & 1 deletion lib/Less/Tree/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function compile( $env ) {
$env->mediaPath = $mediaPathBackup;
$env->mediaBlocks = $mediaPBlocksBackup;

return new Less_Tree_Directive( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo );
return new self( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo );
}

public function variable( $name ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function accept( $visitor ) {
}

public function compile( $env ) {
return new Less_Tree_Element(
return new self(
$this->combinator,
( $this->value_is_object ? $this->value->compile( $env ) : $this->value ),
$this->index,
Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function compile( $env ) {
foreach ( $this->value as $e ) {
$ret[] = $e->compile( $env );
}
$returnValue = new Less_Tree_Expression( $ret );
$returnValue = new self( $ret );

} else {

if ( ( $this->value[0] instanceof Less_Tree_Expression ) && $this->value[0]->parens && !$this->value[0]->parensInOp ) {
if ( ( $this->value[0] instanceof self ) && $this->value[0]->parens && !$this->value[0]->parensInOp ) {
$doubleParen = true;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public function compile( $env ) {
Less_Parser::$has_extends = true;
$this->selector = $this->selector->compile( $env );
return $this;
// return new Less_Tree_Extend( $this->selector->compile($env), $this->option, $this->index);
// return new self( $this->selector->compile($env), $this->option, $this->index);
}

public function clone() {
return new Less_Tree_Extend( $this->selector, $this->option, $this->index );
return new self( $this->selector, $this->option, $this->index );
}

public function findSelfSelectors( $selectors ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getPath() {
}

public function compileForImport( $env ) {
return new Less_Tree_Import( $this->path->compile( $env ), $this->features, $this->options, $this->index, $this->currentFileInfo );
return new self( $this->path->compile( $env ), $this->features, $this->options, $this->index, $this->currentFileInfo );
}

public function compilePath( $env ) {
Expand Down Expand Up @@ -187,7 +187,7 @@ public function compile( $env ) {
// css ?
if ( $evald->css ) {
$features = ( $evald->features ? $evald->features->compile( $env ) : null );
return new Less_Tree_Import( $this->compilePath( $env ), $features, $this->options, $this->index );
return new self( $this->compilePath( $env ), $features, $this->options, $this->index );
}

return $this->ParseImport( $full_path, $uri, $env );
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function genCSS( $output ) {
}

public function compare( $other ) {
if ( $other instanceof Less_Tree_Keyword ) {
if ( $other instanceof self ) {
return $other->value === $this->value ? 0 : 1;
} else {
return -1;
Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function genCSS( $output ) {

/**
* @param Less_Environment $env
* @return Less_Tree_Media|Less_Tree_Ruleset
* @return self|Less_Tree_Ruleset
* @see less-2.5.3.js#Media.prototype.eval
*/
public function compile( $env ) {
$media = new Less_Tree_Media( [], [], $this->index, $this->currentFileInfo );
$media = new self( [], [], $this->index, $this->currentFileInfo );

$strictMathBypass = false;
if ( Less_Parser::$options['strictMath'] === false ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Mixin/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public function compileParams( $env, $mixinFrames, $args = [], &$evaldArguments

public function compile( $env ) {
if ( $this->frames ) {
return new Less_Tree_Mixin_Definition( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $this->frames );
return new self( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $this->frames );
}
return new Less_Tree_Mixin_Definition( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $env->frames );
return new self( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $env->frames );
}

public function evalCall( $env, $args = null, $important = null ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/NameValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function compile( $env ) {
}

public function makeImportant() {
$new = new Less_Tree_NameValue( $this->name, $this->value, $this->index, $this->currentFileInfo );
$new = new self( $this->name, $this->value, $this->index, $this->currentFileInfo );
$new->important = ' !important';
return $new;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Negative.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function compile( $env ) {
$ret = new Less_Tree_Operation( '*', [ new Less_Tree_Dimension( -1 ), $this->value ] );
return $ret->compile( $env );
}
return new Less_Tree_Negative( $this->value->compile( $env ) );
return new self( $this->value->compile( $env ) );
}
}
2 changes: 1 addition & 1 deletion lib/Less/Tree/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function compile( $env ) {
}
}

return new Less_Tree_Operation( $this->op, [ $a, $b ], $this->isSpaced );
return new self( $this->op, [ $a, $b ], $this->isSpaced );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Tree/Paren.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function genCSS( $output ) {
}

public function compile( $env ) {
return new Less_Tree_Paren( $this->value->compile( $env ) );
return new self( $this->value->compile( $env ) );
}

}
4 changes: 2 additions & 2 deletions lib/Less/Tree/Quoted.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function compile( $env ) {
foreach ( $matches[1] as $i => $match ) {
$v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo );
$v = $v->compile( $env );
$v = ( $v instanceof Less_Tree_Quoted ) ? $v->value : $v->toCSS();
$v = ( $v instanceof self ) ? $v->value : $v->toCSS();
$value = str_replace( $matches[0][$i], $v, $value );
}
}

return new Less_Tree_Quoted( $this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo );
return new self( $this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo );
}

public function compare( $x ) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Less/Tree/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function genCSS( $output ) {

/**
* @param Less_Environment $env
* @return Less_Tree_Rule
* @return self
*/
public function compile( $env ) {
$name = $this->name;
Expand All @@ -86,7 +86,7 @@ public function compile( $env ) {
}

if ( Less_Environment::$mixin_stack ) {
$return = new Less_Tree_Rule( $name, $evaldValue, $this->important, $this->merge, $this->index, $this->currentFileInfo, $this->inline );
$return = new self( $name, $evaldValue, $this->important, $this->merge, $this->index, $this->currentFileInfo, $this->inline );
} else {
$this->name = $name;
$this->value = $evaldValue;
Expand Down Expand Up @@ -115,7 +115,7 @@ public function CompileName( $env, $name ) {
}

public function makeImportant() {
return new Less_Tree_Rule( $this->name, $this->value, '!important', $this->merge, $this->index, $this->currentFileInfo, $this->inline );
return new self( $this->name, $this->value, '!important', $this->merge, $this->index, $this->currentFileInfo, $this->inline );
}

}
Loading

0 comments on commit 06ab7ce

Please sign in to comment.