Storyblok::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace Riclep\Storyblok;
5
6
7
use Riclep\Storyblok\Traits\HasChildClasses;
8
use Storyblok\ApiException;
9
10
class Storyblok
11
{
12
	use HasChildClasses;
13
14
15
	/**
16
	 * Reads the requested story from the API
17
	 *
18
	 * @param string $slug
19
	 * @param array|null $resolveRelations
20
	 * @param string|null $language
21
	 * @param string|null $fallbackLanguage
22
	 * @return Page
23
	 * @throws ApiException
24
	 */
25
	public function read(string $slug, array $resolveRelations = null, string $language = null, string $fallbackLanguage = null): Page
26
	{
27
		$storyblokRequest = new RequestStory();
28
29
		if ($resolveRelations) {
30
			$storyblokRequest->resolveRelations($resolveRelations);
31
		}
32
33
		if ($language) {
34
			$storyblokRequest->language($language, $fallbackLanguage);
35
		}
36
37
		$response = $storyblokRequest->get($slug);
38
39
		$class = $this->getChildClassName('Page', $response['content']['component']);
40
41
		return new $class($response);
42
	}
43
44
	/**
45
	 * @param $data
46
	 * @return mixed
47
	 */
48
	public function setData($data): mixed
49
	{
50
		$response = $data;
51
52
		$class = $this->getChildClassName('Page', $response['content']['component']);
53
54
		return new $class($response);
55
	}
56
}