1. Go to this page and download the library: Download scrumble-nl/popo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scrumble-nl / popo example snippets
class ProductPopo extends BasePopo
{
/**
* @var string
*/
public string $name;
/**
* @var float
*/
public float $price;
/**
* @param string $name
* @param float $price
*/
public function __construct(string $name, float $price)
{
$this->name = $name;
$this->price = $price;
}
}
public static function fromApiResponse(array $apiResponse): ProductPopo
{
return new self(
$apiResponse['name'],
(float) $apiResponse['price'],
);
}
/**
* @var Collection<int, CategoryPopo>
*/
public Collection $categories;
use Tests\Popo\ProductPopo;
use Scrumble\Popo\PopoFactory;
class ProductPopoFactory extends PopoFactory
{
/**
* @var null|string
*/
public ?string $popoClass = ProductPopo::class;
/**
* {@inheritDoc}
*/
public function definition(): array
{
return [
'name' => $this->faker->name,
'price' => $this->faker->randomNumber(1, 10),
];
}
}
use Scrumble\Popo\HasPopoFactory;
class ProductPopo extends BasePopo
{
use HasPopoFactory;
/**
* @var string
*/
public string $name;
/**
* @var float
*/
public float $price;
/**
* @param string $name
* @param float $price
*/
public function __construct(string $name, float $price)
{
$this->name = $name;
$this->price = $price;
}
/**
* @return string
*/
public static function popoFactory(): string
{
return ProductPopoFactory::class;
}
}