Insphpect

This tool is currently proof-of-concept. Your feedback and evaluation is valuable in helping to improve it and ensure its reports are meaninful.

Please click here to complete a short survey to tell us what you think. It should take less than 5 minutes and help further this research project!

Transphporm\Parser\Tokenizer

Detected issues

Issue Method Line number
Using `new` in constructor __construct 41
Using `new` in constructor __construct 44

Code

Click highlighted lines for details

<?php/* @description     Transformation Style Sheets - Revolutionising PHP templating    * * @author          Tom Butler tom@r.je                                             * * @copyright       2017 Tom Butler <tom@r.je> | https://r.je/                      * * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License * * @version         1.2                                                             */namespace Transphporm\Parser;class Tokenizer {	private $str;	private $tokenizeRules = [];	const NAME = 'LITERAL';	const STRING = 'STRING';	const OPEN_BRACKET = 'OPEN_BRACKET';	const CLOSE_BRACKET = 'CLOSE_BRACKET';	const OPEN_SQUARE_BRACKET = 'SQUARE_BRACKET';	const CLOSE_SQUARE_BRACKET = 'CLOSE_SQUARE_BRACKET';	const CONCAT = 'CONCAT';	const ARG = 'ARG';	const WHITESPACE = 'WHITESPACE';	const NEW_LINE = 'NEW_LINE';	const DOT = 'DOT';	const NUMERIC = 'NUMERIC';	const EQUALS = 'EQUALS';	const NOT = 'NOT';	const OPEN_BRACE = 'OPEN_BRACE';	const CLOSE_BRACE = 'CLOSE_BRACE';	const BOOL = 'BOOL';	const IN = 'IN';	const COLON = 'COLON';	const SEMI_COLON = 'SEMI_COLON';	const NUM_SIGN = 'NUM_SIGN';	const GREATER_THAN = 'GREATER_THAN';	const LOWER_THAN = 'LOWER_THAN';	const AT_SIGN = 'AT_SIGN';	const SUBTRACT = 'SUBTRACT';	const MULTIPLY = 'MULTIPLY';	const DIVIDE = 'DIVIDE';	public function __construct($str) {

Usage of the new keyword in a constructor

Summary of issues

Background

If a dependency is constructed inside the object that requires it rather than passed in as a reference then flexibility is lost[1][2]

 public class Car {

    private 
Engine engine;
    
    public 
Car() {
        
this.engine = new Engine();
    }
}

Here, the Car constructor creates the Engine instance. This is inflexible as it forces all Car objects to use the exact same Engine type. Instead, it would encourage reuse if the program supported different engine types (e.g. DieselEngine, PetrolEngine or HybridEngine).

The same is true when an instance variable is created when the class is defined:

 public class Car {
    private 
Engine engine = new Engine();
}

By using the new keyword to instantiate a dependency, the specific implementation of that dependency is hardcoded and cannot be substituted.

Instead, the dependency should be constructed outside the class and injected in:

 public class Car {
    private 
Engine engine;

    public 
Car(Engine engine) {
        
this.engine engine;
    }
}

Using dependency injection it is possible to pass in any engine type:

 //Instead of
Car myCar = new Car();

//It's now possible to construct different types of car:
Car petrolCar = new Car(new PetrolEngine);
Car electricCar = new Car(new ElectricEngine);

A secondary advantage to Dependency Injection with regards to flexibility and encapsulation is that the class which has the dependency (Car, in this example) it not aware of the dependencies of the Engine class.

For example, if the Engine class required a Gearbox instance as a constructor argument, the Car class would need to instantiate and pass in the relevant Gearbox instance. And provide any dependencies of the Gearbox class when instantiating it.

If the constructor arguments of any of the classes which need to be instantiated are modified during development, any class which creates an instance of the class must also be modified. A change to the constructor for Engine would require modifying the Car class. Instead, if the fully constructed Engine instance

By loosely coupling the Engine class to the Car class, the author of the Car class does not need to know anything about the implementation of Engine class or have knowledge of what dependencies it has.

 
public Car() {

    
this.engine = new Engine(new Gearbox());
}

Further reading

Additional resources:

References

  1. Hevery, M. (2008) How to Think About the “new” Operator with Respect to Unit Testing [online]. Available from: http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/
  2. Hevery, M. (2008) Code Reviewers Guide [online]. Available from: http://misko.hevery.com/code-reviewers-guide/

Please note: This feature is currently proof-of-concept, the instructions may not always be completely accurate.

\Transphporm\Parser\Tokenizer\TokenizedString is instantiated inside the constructor of Transphporm\Parser\Tokenizer

1) Remove the new expression and replace it with a variable:

 

$this->str = new Tokenizer\TokenizedString($str);

becomes:

 

        $this->str = new Tokenizer\TokenizedString($str);

2) Add a constructor argument for the new variable: Replace:

 

public function __construct($str) {

with:

 

public function __construct($str) {

3) Find any occurance of new Transphporm\Parser\Tokenizer and provide the new dependency.

\Transphporm\Parser\Tokenizer is being instantiated in src/Parser/Value.php:0

Replace:

 

$tokenizer = new Tokenizer($str);

With:

 

$tokenizer = new Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

\Transphporm\Parser\Tokenizer is being instantiated in src/SheetLoader/TSSFile.php:0

Replace:

 

return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer($arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

With:

 

return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

\Transphporm\Parser\Tokenizer is being instantiated in src/SheetLoader/TSSString.php:0

Replace:

 

return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer($arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

With:

 

return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

\Transphporm\Parser\Tokenizer is being instantiated in src/Pseudo/Not.php:0

Replace:

 

$tokenizer = new \Transphporm\Parser\Tokenizer($selector);

With:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

\Transphporm\Parser\Tokenizer is being instantiated in src/TSSFunction/Template.php:0

Replace:

 

$tokenizer = new \Transphporm\Parser\Tokenizer($selector);

With:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

\Transphporm\Parser\Tokenizer is being instantiated in src/TSSValidator.php:0

Replace:

 

return (new Parser\Tokenizer($tss))->getTokens();

With:

Please note: This feature is currently proof-of-concept, this patch may not work, please don't blindly apply it.

diff --git a/src/Builder.php b/src/Builder.php
index 78c369b..225f265 100644
--- a/src/Builder.php
+++ b/src/Builder.php
@@ -82,7 +82,7 @@ class Builder {
 		$elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data);
 		$functionSet = new FunctionSet($elementData);
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
-		$template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>' );
+		$template = new Template(new \DomXPath(false), new \DomDocument, $this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>');

 		$valueParser = new Parser\Value($functionSet);
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
diff --git a/src/Parser/Sheet.php b/src/Parser/Sheet.php
index 06384a2..3834958 100644
--- a/src/Parser/Sheet.php
+++ b/src/Parser/Sheet.php
@@ -15,13 +15,13 @@ class Sheet {
 	private $file;
 	private $rules;

-	public function __construct($tss, CssToXpath $xPath, Value $valueParser, \Transphporm\FilePath $filePath, \Transphporm\SheetLoader\SheetLoader $sheetLoader, $file = null) {
+	public function __construct(\Transphporm\Parser\Tokenizer $tokenizer, $tss, CssToXpath $xPath, Value $valueParser, \Transphporm\FilePath $filePath, \Transphporm\SheetLoader\SheetLoader $sheetLoader, $file = null) {
 		$this->xPath = $xPath;
 		$this->valueParser = $valueParser;
 		$this->filePath = $filePath;
 		$this->sheetLoader = $sheetLoader;
 		$this->file = $file;
-		$this->tss = (new Tokenizer($tss))->getTokens();
+		$this->tss = ($tokenizer)->getTokens();
 	}

 	public function parse($indexStart = 0) {
@@ -115,4 +115,4 @@ class Sheet {

         return $return;
     }
-}
+}
\ No newline at end of file
diff --git a/src/Parser/Tokenizer.php b/src/Parser/Tokenizer.php
index af6d1a3..20d7626 100644
--- a/src/Parser/Tokenizer.php
+++ b/src/Parser/Tokenizer.php
@@ -37,8 +37,8 @@ class Tokenizer {
 	const MULTIPLY = 'MULTIPLY';
 	const DIVIDE = 'DIVIDE';

-	public function __construct($str) {
-		$this->str = new Tokenizer\TokenizedString($str);
+	public function __construct(\Transphporm\Parser\Tokenizer\TokenizedString $tokenizedString, $str) {
+		$this->str = $tokenizedString;

 		$this->tokenizeRules = [
 			new Tokenizer\Comments,
@@ -62,4 +62,4 @@ class Tokenizer {
 		return $tokens;
 	}

-}
+}
\ No newline at end of file
diff --git a/src/Parser/Value.php b/src/Parser/Value.php
index 14097e0..46c7867 100644
--- a/src/Parser/Value.php
+++ b/src/Parser/Value.php
@@ -47,7 +47,9 @@ class Value {
 	}

 	public function parse($str) {
-		$tokenizer = new Tokenizer($str);
+
+$arg0 = $str;
+		$tokenizer = new Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 		$tokens = $tokenizer->getTokens();
 		$this->result = $this->parseTokens($tokens, $this->baseData);
 		return $this->result;
diff --git a/src/Pseudo/Not.php b/src/Pseudo/Not.php
index 384d0b2..c1d29e4 100644
--- a/src/Pseudo/Not.php
+++ b/src/Pseudo/Not.php
@@ -24,7 +24,9 @@ class Not implements \Transphporm\Pseudo {
 	private function notElement($css, $xpath, $element) {

 		foreach ($css as $selector) {
-			$tokenizer = new \Transphporm\Parser\Tokenizer($selector);
+
+$arg0 = $selector;
+			$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 			$xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens());
             $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens());
             $pseudoMatcher = $this->config->createPseudoMatcher($pseudo);
diff --git a/src/SheetLoader/TSSFile.php b/src/SheetLoader/TSSFile.php
index df55c42..7fa321a 100644
--- a/src/SheetLoader/TSSFile.php
+++ b/src/SheetLoader/TSSFile.php
@@ -73,7 +73,11 @@ class TSSFile implements TSSRules {
 		if (empty($rules)) $tss = file_get_contents($this->fileName);
 		else return $rules['rules'];

-		return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
+$arg0 = $tss;
+
+$arg0 = $arg0;
+
+		return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
 	}

 	//write the sheet to cache
diff --git a/src/SheetLoader/TSSString.php b/src/SheetLoader/TSSString.php
index 2e1e39a..bce2f83 100644
--- a/src/SheetLoader/TSSString.php
+++ b/src/SheetLoader/TSSString.php
@@ -24,7 +24,11 @@ class TSSString implements TSSRules {
 	}

 	public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) {
-		return (new \Transphporm\Parser\Sheet($this->str, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
+
+$arg0 = $this->str;
+
+$arg0 = $arg0;
+		return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
 	}

 	public function write($rules, $imports = []) {
diff --git a/src/TSSFunction/Template.php b/src/TSSFunction/Template.php
index c2cdc23..f1ddd97 100644
--- a/src/TSSFunction/Template.php
+++ b/src/TSSFunction/Template.php
@@ -46,7 +46,9 @@ class Template implements \Transphporm\TSSFunction {
 	}

 	private function templateSubsection($doc, $selector) {
-		$tokenizer = new \Transphporm\Parser\Tokenizer($selector);
+
+$arg0 = $selector;
+		$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 		$xpathStr = $this->xPath->getXpath($tokenizer->getTokens());
 		$xpath = new \DomXpath($doc);
 		$nodes = $xpath->query($xpathStr);
diff --git a/src/TSSValidator.php b/src/TSSValidator.php
index f3e5f4b..8c5aef2 100644
--- a/src/TSSValidator.php
+++ b/src/TSSValidator.php
@@ -45,6 +45,8 @@ class TSSValidator {

     private function tokenize($tss) {
         if (is_file($tss)) $tss = file_get_contents($tss);
-        return (new Parser\Tokenizer($tss))->getTokens();
+
+$arg0 = $tss;
+        return (new Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens();
     }
 }
diff --git a/src/Template.php b/src/Template.php
index f46567f..057ff6a 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -14,13 +14,13 @@ class Template {
 	private $save;

 	/** Takes an XML string and loads it into a DomDocument object */
-	public function __construct($doc) {
-		$this->document = new \DomDocument;
+	public function __construct(\DomXPath $domXPath, $doc) {
+		$this->document = $domDocument;
 		//This should remove whitespace left behind after ->removeChild but it doesn't
 		$this->document->preserveWhiteSpace = false;
 		$this->loadDocument($doc);

-		$this->xpath = new \DomXPath($this->document);
+		$this->xpath = $domXPath;
 		$this->xpath->registerNamespace('php', 'http://php.net/xpath');
 		$this->xpath->registerPhpFunctions();

@@ -104,4 +104,4 @@ class Template {
 		return trim($output);
 	}

-}
+}
\ No newline at end of file
$this->tokenizeRules = [

Usage of the new keyword in a constructor

Summary of issues

Background

If a dependency is constructed inside the object that requires it rather than passed in as a reference then flexibility is lost[1][2]

 public class Car {

    private 
Engine engine;
    
    public 
Car() {
        
this.engine = new Engine();
    }
}

Here, the Car constructor creates the Engine instance. This is inflexible as it forces all Car objects to use the exact same Engine type. Instead, it would encourage reuse if the program supported different engine types (e.g. DieselEngine, PetrolEngine or HybridEngine).

The same is true when an instance variable is created when the class is defined:

 public class Car {
    private 
Engine engine = new Engine();
}

By using the new keyword to instantiate a dependency, the specific implementation of that dependency is hardcoded and cannot be substituted.

Instead, the dependency should be constructed outside the class and injected in:

 public class Car {
    private 
Engine engine;

    public 
Car(Engine engine) {
        
this.engine engine;
    }
}

Using dependency injection it is possible to pass in any engine type:

 //Instead of
Car myCar = new Car();

//It's now possible to construct different types of car:
Car petrolCar = new Car(new PetrolEngine);
Car electricCar = new Car(new ElectricEngine);

A secondary advantage to Dependency Injection with regards to flexibility and encapsulation is that the class which has the dependency (Car, in this example) it not aware of the dependencies of the Engine class.

For example, if the Engine class required a Gearbox instance as a constructor argument, the Car class would need to instantiate and pass in the relevant Gearbox instance. And provide any dependencies of the Gearbox class when instantiating it.

If the constructor arguments of any of the classes which need to be instantiated are modified during development, any class which creates an instance of the class must also be modified. A change to the constructor for Engine would require modifying the Car class. Instead, if the fully constructed Engine instance

By loosely coupling the Engine class to the Car class, the author of the Car class does not need to know anything about the implementation of Engine class or have knowledge of what dependencies it has.

 
public Car() {

    
this.engine = new Engine(new Gearbox());
}

Further reading

Additional resources:

References

  1. Hevery, M. (2008) How to Think About the “new” Operator with Respect to Unit Testing [online]. Available from: http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/
  2. Hevery, M. (2008) Code Reviewers Guide [online]. Available from: http://misko.hevery.com/code-reviewers-guide/

Please note: This feature is currently proof-of-concept, the instructions may not always be completely accurate.

\Transphporm\Parser\Tokenizer\Comments is instantiated inside the constructor of Transphporm\Parser\Tokenizer

1) Remove the new expression and replace it with a variable:

 

new Tokenizer\Comments,

becomes:

 

            new Tokenizer\Comments,

2) Add a constructor argument for the new variable: Replace:

 

public function __construct($str) {

with:

 

public function __construct($str) {

3) Find any occurance of new Transphporm\Parser\Tokenizer and provide the new dependency.

\Transphporm\Parser\Tokenizer is being instantiated in src/Parser/Value.php:0

Replace:

 

$tokenizer = new Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

With:

 

$tokenizer = new Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,

\Transphporm\Parser\Tokenizer is being instantiated in src/SheetLoader/TSSFile.php:0

Replace:

 

return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

With:

 

return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,

\Transphporm\Parser\Tokenizer is being instantiated in src/SheetLoader/TSSString.php:0

Replace:

 

return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0$cssToXpath$valueParser$this->filePath$sheetLoader))->parse($indexStart);

With:

 

return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,

\Transphporm\Parser\Tokenizer is being instantiated in src/Pseudo/Not.php:0

Replace:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

With:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,

\Transphporm\Parser\Tokenizer is being instantiated in src/TSSFunction/Template.php:0

Replace:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);

With:

 

$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,

\Transphporm\Parser\Tokenizer is being instantiated in src/TSSValidator.php:0

Replace:

 

return (new Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens();

With:

Please note: This feature is currently proof-of-concept, this patch may not work, please don't blindly apply it.

diff --git a/src/Builder.php b/src/Builder.php
index 78c369b..225f265 100644
--- a/src/Builder.php
+++ b/src/Builder.php
@@ -82,7 +82,7 @@ class Builder {
 		$elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data);
 		$functionSet = new FunctionSet($elementData);
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
-		$template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>' );
+		$template = new Template(new \DomXPath(false), new \DomDocument, $this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>');

 		$valueParser = new Parser\Value($functionSet);
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
diff --git a/src/Parser/Sheet.php b/src/Parser/Sheet.php
index 06384a2..3834958 100644
--- a/src/Parser/Sheet.php
+++ b/src/Parser/Sheet.php
@@ -15,13 +15,13 @@ class Sheet {
 	private $file;
 	private $rules;

-	public function __construct($tss, CssToXpath $xPath, Value $valueParser, \Transphporm\FilePath $filePath, \Transphporm\SheetLoader\SheetLoader $sheetLoader, $file = null) {
+	public function __construct(\Transphporm\Parser\Tokenizer $tokenizer, $tss, CssToXpath $xPath, Value $valueParser, \Transphporm\FilePath $filePath, \Transphporm\SheetLoader\SheetLoader $sheetLoader, $file = null) {
 		$this->xPath = $xPath;
 		$this->valueParser = $valueParser;
 		$this->filePath = $filePath;
 		$this->sheetLoader = $sheetLoader;
 		$this->file = $file;
-		$this->tss = (new Tokenizer($tss))->getTokens();
+		$this->tss = ($tokenizer)->getTokens();
 	}

 	public function parse($indexStart = 0) {
@@ -115,4 +115,4 @@ class Sheet {

         return $return;
     }
-}
+}
\ No newline at end of file
diff --git a/src/Parser/Tokenizer.php b/src/Parser/Tokenizer.php
index af6d1a3..c0f3f22 100644
--- a/src/Parser/Tokenizer.php
+++ b/src/Parser/Tokenizer.php
@@ -37,16 +37,11 @@ class Tokenizer {
 	const MULTIPLY = 'MULTIPLY';
 	const DIVIDE = 'DIVIDE';

-	public function __construct($str) {
-		$this->str = new Tokenizer\TokenizedString($str);
+	public function __construct(\Transphporm\Parser\Tokenizer\Comments $comments, $str) {
+		$this->str = $tokenizedString;

 		$this->tokenizeRules = [
-			new Tokenizer\Comments,
-			new Tokenizer\BasicChars,
-			new Tokenizer\Literals,
-			new Tokenizer\Strings,
-			new Tokenizer\Brackets
-		];
+			$comments;
 	}

 	public function getTokens() {
@@ -62,4 +57,4 @@ class Tokenizer {
 		return $tokens;
 	}

-}
+}
\ No newline at end of file
diff --git a/src/Parser/Value.php b/src/Parser/Value.php
index 14097e0..e4c8527 100644
--- a/src/Parser/Value.php
+++ b/src/Parser/Value.php
@@ -47,7 +47,14 @@ class Value {
 	}

 	public function parse($str) {
-		$tokenizer = new Tokenizer($str);
+
+$arg0 = $str;
+		$tokenizer = new Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 		$tokens = $tokenizer->getTokens();
 		$this->result = $this->parseTokens($tokens, $this->baseData);
 		return $this->result;
diff --git a/src/Pseudo/Not.php b/src/Pseudo/Not.php
index 384d0b2..d9c2f20 100644
--- a/src/Pseudo/Not.php
+++ b/src/Pseudo/Not.php
@@ -24,7 +24,14 @@ class Not implements \Transphporm\Pseudo {
 	private function notElement($css, $xpath, $element) {

 		foreach ($css as $selector) {
-			$tokenizer = new \Transphporm\Parser\Tokenizer($selector);
+
+$arg0 = $selector;
+			$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 			$xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens());
             $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens());
             $pseudoMatcher = $this->config->createPseudoMatcher($pseudo);
diff --git a/src/SheetLoader/TSSFile.php b/src/SheetLoader/TSSFile.php
index df55c42..02b4deb 100644
--- a/src/SheetLoader/TSSFile.php
+++ b/src/SheetLoader/TSSFile.php
@@ -73,7 +73,16 @@ class TSSFile implements TSSRules {
 		if (empty($rules)) $tss = file_get_contents($this->fileName);
 		else return $rules['rules'];

-		return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
+$arg0 = $tss;
+
+$arg0 = $arg0;
+
+		return $tss == null ? [] : (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
 	}

 	//write the sheet to cache
diff --git a/src/SheetLoader/TSSString.php b/src/SheetLoader/TSSString.php
index 2e1e39a..78f94df 100644
--- a/src/SheetLoader/TSSString.php
+++ b/src/SheetLoader/TSSString.php
@@ -24,7 +24,16 @@ class TSSString implements TSSRules {
 	}

 	public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) {
-		return (new \Transphporm\Parser\Sheet($this->str, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
+
+$arg0 = $this->str;
+
+$arg0 = $arg0;
+		return (new \Transphporm\Parser\Sheet(new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens(), $arg0, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
 	}

 	public function write($rules, $imports = []) {
diff --git a/src/TSSFunction/Template.php b/src/TSSFunction/Template.php
index c2cdc23..042f44c 100644
--- a/src/TSSFunction/Template.php
+++ b/src/TSSFunction/Template.php
@@ -46,7 +46,14 @@ class Template implements \Transphporm\TSSFunction {
 	}

 	private function templateSubsection($doc, $selector) {
-		$tokenizer = new \Transphporm\Parser\Tokenizer($selector);
+
+$arg0 = $selector;
+		$tokenizer = new \Transphporm\Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0);
 		$xpathStr = $this->xPath->getXpath($tokenizer->getTokens());
 		$xpath = new \DomXpath($doc);
 		$nodes = $xpath->query($xpathStr);
diff --git a/src/TSSValidator.php b/src/TSSValidator.php
index f3e5f4b..39ad561 100644
--- a/src/TSSValidator.php
+++ b/src/TSSValidator.php
@@ -45,6 +45,13 @@ class TSSValidator {

     private function tokenize($tss) {
         if (is_file($tss)) $tss = file_get_contents($tss);
-        return (new Parser\Tokenizer($tss))->getTokens();
+
+$arg0 = $tss;
+        return (new Parser\Tokenizer(new \Transphporm\Parser\Tokenizer\Comments,
+			new Tokenizer\BasicChars,
+			new Tokenizer\Literals,
+			new Tokenizer\Strings,
+			new Tokenizer\Brackets
+		], new \Transphporm\Parser\Tokenizer\TokenizedString($arg0), $arg0))->getTokens();
     }
 }
diff --git a/src/Template.php b/src/Template.php
index f46567f..057ff6a 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -14,13 +14,13 @@ class Template {
 	private $save;

 	/** Takes an XML string and loads it into a DomDocument object */
-	public function __construct($doc) {
-		$this->document = new \DomDocument;
+	public function __construct(\DomXPath $domXPath, $doc) {
+		$this->document = $domDocument;
 		//This should remove whitespace left behind after ->removeChild but it doesn't
 		$this->document->preserveWhiteSpace = false;
 		$this->loadDocument($doc);

-		$this->xpath = new \DomXPath($this->document);
+		$this->xpath = $domXPath;
 		$this->xpath->registerNamespace('php', 'http://php.net/xpath');
 		$this->xpath->registerPhpFunctions();

@@ -104,4 +104,4 @@ class Template {
 		return trim($output);
 	}

-}
+}
\ No newline at end of file
new Tokenizer\BasicChars, new Tokenizer\Literals, new Tokenizer\Strings, new Tokenizer\Brackets ]; } public function getTokens() { $tokens = new Tokens; $this->str->reset(); while ($this->str->next()) { foreach ($this->tokenizeRules as $tokenizer) { $tokenizer->tokenize($this->str, $tokens); } } return $tokens; }}