Completed
Push — master ( ce557b...46a40a )
by Marko
02:10
created

Scene::meta()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 22
    public function __construct($name)
37
    {
38 22
        $this->name = $name;
39 22
    }
40
41
    /**
42
     * Scene DOMDocument meta tags object
43
     *
44
     * @return \AframeVR\Core\Helpers\MetaTags
45
     */
46 1
    public function meta()
47
    {
48 1
        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 bool $full            
55
     * @param bool $print            
56
     */
57 1
    public function render($full = true, $print = 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...
58
    {
59 1
        $dom = new DOMImplementation();
60 1
        $doctype = $dom->createDocumentType('html');
61 1
        $aframe_dom = $dom->createDocument(null, 'html', $doctype);
62 1
        $aframe_dom_head = $aframe_dom->createElement('head');
63 1
        $aframe_dom_body = $aframe_dom->createElement('body', "\n");
64 1
        $aframe_dom_scene = $aframe_dom->createElement("a-scene", "\n");
65
        
66
        /* Add metatags */
67 1
        $this->meta()->DOMAppendTags($aframe_dom, $aframe_dom_head);
68
        
69
        /* Add primitives to DOM */
70 1
        $this->DOMAppendPrimitives($aframe_dom, $aframe_dom_scene);
71
        
72 1
        $cdn_script = $aframe_dom->createElement('script');
73 1
        $cdn_script->setAttribute('src', 'https://aframe.io/releases/0.2.0/aframe.min.js');
74 1
        $aframe_dom_head->appendChild($cdn_script);
75
        
76
        /* Pull DOM together */
77 1
        $aframe_dom_body->appendChild($aframe_dom_scene);
78 1
        $html = $aframe_dom->getElementsByTagName('html')[0];
79 1
        $html->appendChild($aframe_dom_head);
80 1
        $html->appendChild($aframe_dom_body);
81
        
82 1
        $aframe_dom->formatOutput = true;
83
        
84
        /* Print Scene */
85 1
        if($print)
86
            print $aframe_dom->saveHTML();
87
        else 
88 1
            return $aframe_dom->saveHTML();
89
    }
90
}
91