for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace VGirol\JsonApiFaker\Factory;
trait HasData
{
/**
* Undocumented variable
*
* @var ResourceIdentifierFactory|ResourceObjectFactory|CollectionFactory|null
*/
public $data = null;
* Undocumented function
* @param ResourceIdentifierFactory|ResourceObjectFactory|CollectionFactory|null $data
* @return static
public function setData($data)
$this->data = $data;
return $this;
}
* @param integer $options
* @param integer $count
public function fakeData($options = null, $count = null)
if (is_null($options)) {
$options = self::FAKE_RESOURCE_OBJECT | self::FAKE_COLLECTION;
VGirol\JsonApiFaker\Fact...a::FAKE_RESOURCE_OBJECT
VGirol\JsonApiFaker\Fact...asData::FAKE_COLLECTION
$count = 5;
$faker = \Faker\Factory::create();
if ($options & self::FAKE_CAN_BE_NULL) {
VGirol\JsonApiFaker\Fact...sData::FAKE_CAN_BE_NULL
if ($faker->boolean) {
$this->setData(null);
$class = (($options & self::FAKE_RESOURCE_IDENTIFIER) == self::FAKE_RESOURCE_IDENTIFIER) ?
VGirol\JsonApiFaker\Fact...AKE_RESOURCE_IDENTIFIER
ResourceIdentifierFactory::class : ResourceObjectFactory::class;
if ($options & self::FAKE_COLLECTION) {
$data = (new CollectionFactory)->fake($options, $count);
} else {
$data = (new $class)->fake();
$this->setData($data);