Issues (20)

src/Space.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chipmunk;
6
7
use Chipmunk\Exception\LogicException;
8
9
class Space extends AbstractFfi
10
{
11
    private Vector $gravity;
12
13
    /**
14
     * Will get the reference on the first Space::getStaticBody() call, then
15
     * will always return the same instance
16
     */
17
    private ?Body $staticBody = null;
18
19
    public function __construct()
20
    {
21
        parent::__construct();
22
23
        $this->setCData($this->getFfi()->cpSpaceNew());
0 ignored issues
show
The method cpSpaceNew() does not exist on FFI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $this->setCData($this->getFfi()->/** @scrutinizer ignore-call */ cpSpaceNew());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
    }
25
26
    public function setGravity(Vector $gravity)
27
    {
28
        $this->gravity = $gravity;
29
30
        $this->getFfi()->cpSpaceSetGravity($this->getCData(), $this->gravity->getCData());
0 ignored issues
show
The method cpSpaceSetGravity() does not exist on FFI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        $this->getFfi()->/** @scrutinizer ignore-call */ cpSpaceSetGravity($this->getCData(), $this->gravity->getCData());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
    }
32
33
    /**
34
     * The Space provided static body for a given cpSpace.
35
     * This is merely provided for convenience and you are not required to use it.
36
     */
37
    public function getStaticBody(): Body
38
    {
39
        if (null === $this->staticBody) {
40
            $this->setStaticBody(Body::fromSpace($this));
41
        }
42
43
        return $this->staticBody;
44
    }
45
46
    /**
47
     * Should be called only in the constructor
48
     *
49
     * @todo Check Chipmunk's way to handle setting a new static body
50
     * @throws LogicException
51
     */
52
    public function setStaticBody(Body $staticBody): self
53
    {
54
        // TODO
55
        // if (null !== $this->staticBody) {
56
        //     throw new LogicException("Attempted to replace an already initialized Space's body");
57
        // }
58
59
        $this->staticBody = $staticBody;
60
61
        return $this;
62
    }
63
64
    public function addShape(Shape $shape): self
65
    {
66
        $this->getFfi()->cpSpaceAddShape($this->getCData(), $shape->getCData());
0 ignored issues
show
The method cpSpaceAddShape() does not exist on FFI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $this->getFfi()->/** @scrutinizer ignore-call */ cpSpaceAddShape($this->getCData(), $shape->getCData());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        return $this;
69
    }
70
}
71