Selaa lähdekoodia

Add code comment

Laurent Destailleur 1 vuosi sitten
vanhempi
commit
ab775998d1

+ 1 - 1
dev/tools/rector/README.md

@@ -18,5 +18,5 @@ composer install
 ##### To make changes on a given directory
 
 ```shell
-./vendor/bin/rector process [--dry-run] ../../../htdocs/core/
+./vendor/bin/rector process [--dry-run] [--clear-cache] ../../../htdocs/core/
 ```

+ 13 - 1
dev/tools/rector/rector.php

@@ -8,6 +8,7 @@ use Rector\Set\ValueObject\LevelSetList;
 
 return static function (RectorConfig $rectorConfig): void {
 	$rectorConfig->phpVersion(PhpVersion::PHP_71);
+	//$rectorConfig->indent(' ', 4);
 	$rectorConfig->paths([
 		__DIR__ . '/../../../htdocs/',
 		__DIR__ . '/../../../scripts/',
@@ -15,12 +16,23 @@ return static function (RectorConfig $rectorConfig): void {
 	]);
 	$rectorConfig->skip([
 		'**/includes/**',
+		__DIR__ . '/../../../htdocs/custom',
 		__DIR__ . '/../../../htdocs/install/doctemplates/*'
 	]);
 	$rectorConfig->parallel(240);
 
 
-	// register a single rule
+	// register rules
+
+	// Remove use of list($a, $b) = ...
+	//$rectorConfig->rule(Rector\Php71\Rector\List_\ListToArrayDestructRector::class);
+	//$rectorConfig->rule(Rector\Php72\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector::class);
+	//$rectorConfig->rule(Rector\Php72\Rector\FuncCall\GetClassOnNullRector::class);
+	//$rectorConfig->rule(Rector\Php72\Rector\Assign\ListEachRector::class);
+	//$rectorConfig->rule(Rector\Php72\Rector\FuncCall\ParseStrWithResultArgumentRector::class);
+	//$rectorConfig->rule(ReplaceEachAssignmentWithKeyCurrentRector::class);
+	//$rectorConfig->rule(Rector\Php72\Rector\FuncCall\StringifyDefineRector::class);
+
 	$rectorConfig->rule(Dolibarr\Rector\Renaming\GlobalToFunction::class);
 	$rectorConfig->rule(Dolibarr\Rector\Renaming\UserRightsToFunction::class);
 

+ 11 - 9
dev/tools/rector/src/Renaming/GlobalToFunction.php

@@ -58,9 +58,9 @@ class GlobalToFunction extends AbstractRector
 	}
 
 	/**
-	 * getNodeTypes
+	 * Return a node type from https://github.com/rectorphp/php-parser-nodes-docs/
 	 *
-	 * @return array
+	 * @return string[]
 	 */
 	public function getNodeTypes(): array
 	{
@@ -70,8 +70,8 @@ class GlobalToFunction extends AbstractRector
 	/**
 	 * refactor
 	 *
-	 * @param Node $node A node
-	 * @return    Equal|Concat|ArrayDimFetch|void
+	 * @param Node 	$node 		A node
+	 * @return    				Equal|Concat|ArrayDimFetch|void
 	 */
 	public function refactor(Node $node)
 	{
@@ -136,6 +136,7 @@ class GlobalToFunction extends AbstractRector
 			return;
 		}
 
+		// Test the type after the comparison conf->global->xxx to know the name of function
 		switch ($node->right->getType()) {
 			case 'Scalar_LNumber':
 				$funcName = 'getDolGlobalInt';
@@ -146,6 +147,7 @@ class GlobalToFunction extends AbstractRector
 			default:
 				return;
 		}
+
 		$constName = $this->getConstName($node->left);
 		if (empty($constName)) {
 			return;
@@ -190,10 +192,10 @@ class GlobalToFunction extends AbstractRector
 	}
 
 	/**
-	 * Check node is global access
+	 * Check if node is a global access with format conf->global->XXX
 	 *
-	 * @param Node $node A node
-	 * @return bool
+	 * @param Node 	$node 	A node
+	 * @return bool			Return true if noe is conf->global->XXX
 	 */
 	private function isGlobalVar($node)
 	{
@@ -214,8 +216,8 @@ class GlobalToFunction extends AbstractRector
 	}
 
 	/**
-	 * @param Node $node node to be parsed
-	 * @return Node|void
+	 * @param 	Node 		$node 	Node to be parsed
+	 * @return 	Node|void			Return the name of the constant
 	 */
 	private function getConstName($node)
 	{

+ 2 - 0
dev/tools/rector/src/Renaming/UserRightsToFunction.php

@@ -40,6 +40,8 @@ class UserRightsToFunction extends AbstractRector
 	}
 
 	/**
+	 * Return a node type from https://github.com/rectorphp/php-parser-nodes-docs/
+	 *
 	 * @return string[]
 	 */
 	public function getNodeTypes(): array