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)
$properties = ['name', 'slug', 'personCount', 'sha', 'statementCount', 'popoloUrl'];
foreach ($properties as $k) {
$this->$k = 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;
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: