Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
LinksMap
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
156
0.00% covered (danger)
0.00%
0 / 1
 mergeWith
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
 asMergedWith
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 withoutShape
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 asAllMovedToKeys
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 __toString
n/a
0 / 0
n/a
0 / 0
2
1<?php declare( strict_types=1 );
2
3namespace SecurityCheckPlugin;
4
5use Phan\Language\Element\FunctionInterface;
6use SplObjectStorage;
7
8/**
9 * Convenience class for better type inference.
10 *
11 * @extends SplObjectStorage<FunctionInterface,SingleMethodLinks>
12 * @method SingleMethodLinks offsetGet( FunctionInterface $object )
13 * @method FunctionInterface current()
14 * XXX: the above `@method` annotations are needed for PHPStorm...
15 */
16class LinksMap extends SplObjectStorage {
17    public function mergeWith( self $other ): void {
18        foreach ( $other as $method ) {
19            if ( $this->offsetExists( $method ) ) {
20                $this[$method] = $this[$method]->asMergedWith( $other[$method] );
21            } else {
22                $this->offsetSet( $method, $other[$method] );
23            }
24        }
25    }
26
27    public function asMergedWith( self $other ): self {
28        $ret = clone $this;
29        $ret->mergeWith( $other );
30        return $ret;
31    }
32
33    public function withoutShape( self $other ): self {
34        $ret = clone $this;
35        foreach ( $other as $func ) {
36            if ( $ret->offsetExists( $func ) ) {
37                $newFuncData = $ret[$func]->withoutShape( $other[$func] );
38                if ( $newFuncData->getParams() ) {
39                    $ret[$func] = $newFuncData;
40                } else {
41                    unset( $ret[$func] );
42                }
43            }
44        }
45        return $ret;
46    }
47
48    public function asAllMovedToKeys(): self {
49        $ret = new self;
50        foreach ( $this as $func ) {
51            $ret[$func] = $this[$func]->asAllParamsMovedToKeys();
52        }
53        return $ret;
54    }
55
56    /**
57     * @codeCoverageIgnore
58     */
59    public function __toString(): string {
60        $children = [];
61        foreach ( $this as $func ) {
62            $children[] = $func->getFQSEN()->__toString() . ': ' . $this[$func]->__toString();
63        }
64        return '{ ' . implode( ',', $children ) . ' }';
65    }
66}