Completed
Push — master ( 94f348...ce557b )
by Marko
02:44
created

Scene::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 20, 2016 - 9:01:22 PM
5
 * Contact      [email protected]
6
 * @copyright   2016 Marko Kungla - https://github.com/mkungla
7
 * @license     The MIT License (MIT)
8
 * 
9
 * @category       AframeVR
10
 * @package        aframe-php
11
 * 
12
 * Lang         PHP (php version >= 7)
13
 * Encoding     UTF-8
14
 * File         Scene.php
15
 * Code format  PSR-2 and 12
16
 * @link        https://github.com/mkungla/aframe-php
17
 ^ @issues      https://github.com/mkungla/aframe-php/issues
18
 * ********************************************************************
19
 * Contributors:
20
 * @author Marko Kungla <[email protected]>
21
 * ********************************************************************
22
 * Comments:
23
 * @formatter:on */
24
namespace AframeVR\Core;
25
26
use \AframeVR\Core\Helpers\MetaTags;
27
use \AframeVR\Extras\Primitives;
28
use \DOMImplementation;
29
30
final class Scene
31
{
32
    use Primitives;
33
34
    private $name;
35
36 9
    public function __construct($name)
37
    {
38 9
        $this->name = $name;
39 9
    }
40
41
    /**
42
     * Scene DOMDocument meta tags object
43
     *
44
     * @return \AframeVR\Core\Helpers\MetaTags
45
     */
46
    public function meta()
47
    {
48
        return $this->meta ?? $this->meta = new MetaTags();
0 ignored issues
show
Bug introduced by
The property meta does not exist. Did you maybe forget to declare it?

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;
Loading history...
49
    }
50
51
    /**
52
     * Render the A-Frame scene
53
     *
54
     * @param string $full            
0 ignored issues
show
Documentation introduced by
Should the type for parameter $full not be boolean|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
55
     */
56
    public function render($full = true)
0 ignored issues
show
Unused Code introduced by
The parameter $full is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        $dom = new DOMImplementation();
59
        $doctype = $dom->createDocumentType('html');
60
        $aframe_dom = $dom->createDocument(null, 'html', $doctype);
61
        $aframe_dom_head = $aframe_dom->createElement('head');
62
        $aframe_dom_body = $aframe_dom->createElement('body', "\n");
63
        $aframe_dom_scene = $aframe_dom->createElement("a-scene", "\n");
64
        
65
        /* Add metatags */
66
        $this->meta()->DOMAppendTags($aframe_dom, $aframe_dom_head);
67
        
68
        /* Add primitives to DOM */
69
        $this->DOMAppendPrimitives($aframe_dom, $aframe_dom_scene);
70
        
71
        $cdn_script = $aframe_dom->createElement('script');
72
        $cdn_script->setAttribute('src', 'https://aframe.io/releases/0.2.0/aframe.min.js');
73
        $aframe_dom_head->appendChild($cdn_script);
74
        
75
        /* Pull DOM together */
76
        $aframe_dom_body->appendChild($aframe_dom_scene);
77
        $html = $aframe_dom->getElementsByTagName('html')[0];
78
        $html->appendChild($aframe_dom_head);
79
        $html->appendChild($aframe_dom_body);
80
        
81
        $aframe_dom->formatOutput = true;
82
        
83
        /* Print Scene */
84
        print $aframe_dom->saveHTML();
85
    }
86
}
87