for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace EveryPolitician\EveryPolitician;
class Legislature
{
public $name;
public $slug;
public $personCount;
public $sha;
public $statementCount;
public $popoloUrl;
protected $legislatureData;
protected $country;
public function __construct($legislatureData, $country)
$propertyMappings = [
'name' => 'name',
'slug' => 'slug',
'person_count' => 'personCount',
'sha' => 'sha',
'statement_count' => 'statementCount',
'popolo_url' => 'popoloUrl'
];
foreach ($propertyMappings as $k => $v) {
$this->$v = array_key_exists($k, $legislatureData) ? $legislatureData[$k] : null;
}
$timestamp = $legislatureData['lastmod'];
$this->lastmod = \DateTime::createFromFormat('U', $timestamp);
lastmod
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;
$this->legislatureData = $legislatureData;
$this->country = $country;
public function __toString()
return '<Legislature: '.$this->name.' in '.$this->country->name.'>';
/**
* Return the directory path in the everypolitician-data repository
*/
public function directory()
$splitPath = explode('/', $this->legislatureData['sources_directory']);
$splitPath = array_slice($splitPath, 1, 2);
return implode('/', $splitPath);
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: