- Extension ID
- What's new?
- Description
- Supported versions
- Function Point, Quality and Sizing support
- Compatibility
- Download and installation instructions
- Prepare and deliver the source code
- What results can you expect?
- Logging mechanism
- Known limitations
- License agreements
Summary: This document provides information about the extension providing PHP support.
Extension ID
com.castsoftware.php
What's new?
Please see PHP 3.1 - Release Notes for more information.
Description
This extension provides support for applications written using the PHP language.
Supported versions
This version of the extension provides support for:
Technology | Supported | Notes |
---|---|---|
PHP 5.x | - | |
Symfony Framework | Doctrine is NOT supported. |
Function Point, Quality and Sizing support
- Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
- Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points (transactions) | |
---|---|
Quality and Sizing |
Compatibility
AIP Core release | Supported? |
---|---|
8.3.x |
Download and installation instructions
The extension will be automatically downloaded and installed in CAST Imaging Console when you deliver PHP code. You can also manually install the extension using the Application - Extensions interface. Once the extension is downloaded and installed, you can now package your source code and run an analysis.
Upgrading from previous releases of the PHP Analyzer
Previous releases of the PHP Analyzer required that an instance of PHP was installed on the Node (i.e. the machine on which the analysis is run). This requirement has been removed in ≥ 3.1.0. The PHP Analyzer now uses an instance of PHP embedded within the extension (v. 5.4.3). Therefore, please note the following:
- If you have already installed a previous version of the PHP Analyzer on your Node and already have a functioning PHP install from that extension, please ensure that you uninstall PHP before proceeding with the instructions below. To remove the PHP installation provided with the PHP Analyzer:
- delete the folder into which it was installed (by default this is usually set to C:\php).
- delete the system environment variable PHP_HOME
- Please check that you do not have an existing third party (i.e. not provided by CAST) installation of PHP on this machine. If a third party installation of PHP already exists, please follow the PHP uninstall procedure for the install method that was used, before starting an analysis. Third party PHP installations are not compatible with the PHP extension.
Prepare and deliver the source code
Source code preparation
- Only files with following extensions will be analyzed *.php; *.php4; *.php5; *.php6; *.inc; *.phtml. The *.yml and *.yaml extensions are also supported for Symfony framework.
- The analysis of XML and XSL files contained in the PHP application is not supported.
- The analysis of any HTML and JavaScript source code delivered with the PHP code is managed by the HTML and JavaScript extension / .NET analyzer, to be configured in addition to the PHP analysis.
Source code preprocessing
PHP source code needs to be preprocessed so that CAST can understand it and analyze it correctly. This code preprocessing is actioned automatically when an analysis is launched or a snapshot is generated (the code is preprocessed before the analysis starts). In other words you only need to package, deliver and launch an analysis/generate a snapshot for the preprocessing to be completed. The PHP Preprocessor log file is stored in the following location:
%PROGRAMDATA%\CAST\CAST\Logs\<application_name>\Execute_Analysis_<guid>\com.castsoftware.php.<_extension_version>.prepro_YYYYMMDDHHMMSS.log
Short tags
PHP short tags <? and <?= in the delivered source code cannot be handled as is, therefor the analyzer will automatically convert them to <?php tags with an added comment, for example: <?=$string?> will be transformed into <?php /*php short tag*/echo $string>.
What results can you expect?
PHP Objects
Icon | Metamodel Name |
---|---|
PHP Array | |
PHP Class | |
PHP Class Constant | |
PHP Constructor | |
PHP Define | |
PHP Function | |
PHP Interface | |
PHP Member | |
PHP Method | |
PHP Section | |
Script Function | |
Script Section |
Symfony Framework objects
Icon | Metamodel Name |
---|---|
PHP Symfony Controller | |
PHP Symfony Controller Class | |
PHP Symfony Route | |
PHP Symfony Service |
All Symfony objects will appear under their respective folders as shown below :
PHP Symfony Controller Class
- Supported scenario: If the Class name ends with Controller, we will create PHP Symfony Controller Class objects
- Links:
- PHP Symfony Controller Class --- Refer Link ---> PHP Class
- Limitations: Alternate syntax where you can give the class name that does not have suffix "Controller" is not supported
PHP Symfony Controller
- Supported scenario: If the method or function ends with suffix "Action", then PHP Symfony Controller Object will be created
- Links:
- PHP Symfony Controller --- Refer Link ---> PHP Symfony Route
- PHP Symfony Controller --- Refer Link ---> PHP Method\Function
PHP Symfony Route
- Supported scenario:
- If a route has been declared in the yml file, a route object will be created
- If a route has been declared in PHP file an annotation route object will be created as follows:
- Default naming convention for route annotation when declared without name above class "<classname>_Class_Annotation_<number>"
- Default naming convention for route annotation when declared without name above method "<methodname>_Method_Annotation_<number>"
- Links:
- PHP Symfony Route --- Call Link ---> PHP Symfony Controller
PHP Symfony Service
- Supported scenario: If a service has been declared in the yml configuration files, PHP Symfony Service Object will be created
- Links:
- PHP Symfony Service --- Call Link ---> PHP Method
- PHP Symfony Service --- Call Link ---> PHP Property
- PHP Symfony Service --- Call Link ---> PHP Class constructor
- Limitation: Inheritance is not supported while determining property setter or constructor injection - they need to be defined in the same class which is being referred to in the service
Structural Rules
The following structural rules are provided:
You can also find a global list here:
https://technologies.castsoftware.com/rules?sec=t_1017000&ref=||
Logging mechanism
Analysis log files
Analysis logs are stored in the default locations.
PHP Preprocessor
PHP Preprocessor log file name (the preprocessor is launched automatically during an analysis) would be in format com.castsoftware.php.prepro_<ExtensionVersion>_<YYYYMMDDHHMMSS>.log
PHP Plugin
PHP Plugin, which uses PHP CodeSniffer, PDepend, PMD, log file name (the PHP Plugin is launched automatically during an analysis) would be of format com.castsoftware.php.plugin_<ExtensionVersion>_<YYYYMMDDHHMMSS>.log.
Errors and Warnings
The PHP configuration included in the extension uses external plugins. During the analysis, the Universal Analyzer or the plugin can throw errors or warnings. The table below list the most significant errors/warnings and lists a suggested remediation action:
Tool | Error or Warning | Action |
---|---|---|
Analyzer & Code Sniffer | UA Plugin : No property (......) found in meta model for php... | No action required. The analyzer is telling you that not all the properties are considered to be injected into the Analysis Service. |
Known limitations
Autowiring
This extension does not support PHP autowiring (see https://php-di.org/doc/autowiring.html).
LISA path length limited to 256 characters
If the LISA (Large Intermediate Storage Area) path for a specific file exceeds 256 characters the following occurs:
- violation calculation for this file will fail with message "<filepath> does not exist".
- the analysis may fail with the error "Error while executing C:\php\phpmd.bat:The given file "<filepath>" does not exist.
This warning will appear in com.castsoftware.plugin*.log file. This is a limitation of PHP itself and not the PHP extension. To remediate this issue reduce path to the LISA folder where possible.
Name matching links - Universal Analyzer limitation
Due to a limitation in the Universal Analyzer (the "engine" used for PHP analyses), links will be created from any name to any matching name. At a minimum the following rule may be impacted and give erroneous results:
ID | Name |
---|---|
1007004 | Avoid Methods and Functions with High Fan-In (PHP) |
1007006 | Avoid Methods and Functions with High Fan-Out (PHP) |
1007008 | Avoid JavaScript Functions with High Fan-In (PHP) |
1007010 | Avoid JavaScript Functions with High Fan-Out (PHP) |
1007168 | Avoid using function or method return value that do not have return (PHP) |
1007170 | Avoid function return value ignored (PHP) |
Analysis of XML and XSL files contained in the PHP application
The analysis of XML and XSL files contained in the PHP application is not supported. Any links between these files and any other file in the application will not be detected. This will impact the results of all the Quality Rules using these files.
Support of JavaScript source code
The PHP extension does not support JavaScript and as such, any JavaScript source code located in PHP or JavaScript files will not be analyzed. CAST recommends using the HTML5 and JavaScript extension to analyze JavaScript files in the source code.
Support of PHTML files
PHTML files are supported with some limitations. If the files contain calls to functions or methods defined in other files and these other files are not specifically included, then these links will be lost.
Missing Links
If a php class has members declared on the same line, only the first member will be detected. For example:
class Test { public $first, $second, $third; }
After analysis only object for "first" will be created.
Limitations specific to rules
Avoid artifacts having recursive calls
"Avoid artifacts having recursive calls" (7388 - a standard CAST rule) - in some cases, a false positive may be detected: a call to a parent function can be detected as a recursive call
Avoid using break or continue statements in loops with high cyclomatic complexity
"Avoid using break or continue statements in loops with high cyclomatic complexity" (1007176) - if the break statement is located in JavaScript functions, no violations will be detected. JavaScript source code located in .PHP or JavaScript files is not analyzed (see limitation listed above).
Avoid unreferenced PHP Files
The rule "Avoid unreferenced PHP Files" (1007052) will return a false positive violation when a PHP file is referenced only from other technologies, for example from only within html/javascript source code.
License agreements
The PHP extension uses several third-party tools. The Licence Agreements for these tools are listed below: