for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Reads a composer.json file and provides accessors to get
* its hash and the required dependencies
*
* @since 1.25
*/
class ComposerJson {
* @param string $location
public function __construct( $location ) {
$this->contents = json_decode( file_get_contents( $location ), true );
contents
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* Dependencies as specified by composer.json
* @return array
public function getRequiredDependencies() {
$deps = [];
if ( isset( $this->contents['require'] ) ) {
foreach ( $this->contents['require'] as $package => $version ) {
if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
$deps[$package] = self::normalizeVersion( $version );
return $deps;
* Strip a leading "v" from the version name
* @param string $version
* @return string
public static function normalizeVersion( $version ) {
if ( strpos( $version, 'v' ) === 0 ) {
// Composer auto-strips the "v" in front of the tag name
$version = ltrim( $version, 'v' );
return $version;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: