Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| SingleMethodLinks | |
0.00% |
0 / 36 |
|
0.00% |
0 / 10 |
420 | |
0.00% |
0 / 1 |
| instanceWithParam | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| withParam | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| asMergedWith | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| withoutShape | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| withOffsetPushedToAll | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| asAllParamsMovedToKeys | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasParam | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParamOffsets | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withOnlyParams | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| __toString | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| 1 | <?php declare( strict_types=1 ); |
| 2 | |
| 3 | namespace SecurityCheckPlugin; |
| 4 | |
| 5 | use ast\Node; |
| 6 | |
| 7 | /** |
| 8 | * Links for a single method |
| 9 | */ |
| 10 | class SingleMethodLinks { |
| 11 | /** |
| 12 | * @var ParamLinksOffsets[] |
| 13 | */ |
| 14 | private $params = []; |
| 15 | |
| 16 | public static function instanceWithParam( int $i, int $initialFlags ): self { |
| 17 | static $singletons = []; |
| 18 | $singletonKey = "$i-$initialFlags"; |
| 19 | if ( !isset( $singletons[$singletonKey] ) ) { |
| 20 | $singletons[$singletonKey] = ( new self() )->withParam( $i, $initialFlags ); |
| 21 | } |
| 22 | return $singletons[$singletonKey]; |
| 23 | } |
| 24 | |
| 25 | public function withParam( int $i, int $flags ): self { |
| 26 | $ret = clone $this; |
| 27 | $ret->params[$i] = ParamLinksOffsets::getInstance( $flags ); |
| 28 | return $ret; |
| 29 | } |
| 30 | |
| 31 | public function asMergedWith( self $other ): self { |
| 32 | $ret = clone $this; |
| 33 | foreach ( $other->params as $i => $otherPar ) { |
| 34 | if ( isset( $ret->params[$i] ) ) { |
| 35 | $ret->params[$i] = $ret->params[$i]->asMergedWith( $otherPar ); |
| 36 | } else { |
| 37 | $ret->params[$i] = $otherPar; |
| 38 | } |
| 39 | } |
| 40 | return $ret; |
| 41 | } |
| 42 | |
| 43 | public function withoutShape( self $other ): self { |
| 44 | $ret = clone $this; |
| 45 | foreach ( $other->params as $i => $otherParam ) { |
| 46 | if ( isset( $ret->params[$i] ) ) { |
| 47 | $newParamData = $ret->params[$i]->withoutShape( $otherParam ); |
| 48 | if ( !$newParamData->isEmpty() ) { |
| 49 | $ret->params[$i] = $newParamData; |
| 50 | } else { |
| 51 | unset( $ret->params[$i] ); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return $ret; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @param Node|string|int|bool|float|null $offset |
| 60 | */ |
| 61 | public function withOffsetPushedToAll( mixed $offset ): self { |
| 62 | $ret = clone $this; |
| 63 | foreach ( $ret->params as $i => $_ ) { |
| 64 | $ret->params[$i] = $ret->params[$i]->withOffsetPushed( $offset ); |
| 65 | } |
| 66 | return $ret; |
| 67 | } |
| 68 | |
| 69 | public function asAllParamsMovedToKeys(): self { |
| 70 | $ret = new self; |
| 71 | foreach ( $this->params as $i => $offsets ) { |
| 72 | $ret->params[$i] = $offsets->asMovedToKeys(); |
| 73 | } |
| 74 | return $ret; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @todo Try to avoid this method |
| 79 | * @return ParamLinksOffsets[] |
| 80 | */ |
| 81 | public function getParams(): array { |
| 82 | return $this->params; |
| 83 | } |
| 84 | |
| 85 | public function hasParam( int $x ): bool { |
| 86 | return isset( $this->params[$x] ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @note This will fail hard if unset. |
| 91 | */ |
| 92 | public function getParamOffsets( int $x ): ParamLinksOffsets { |
| 93 | return $this->params[$x]; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param int[] $params |
| 98 | */ |
| 99 | public function withOnlyParams( array $params ): self { |
| 100 | $ret = clone $this; |
| 101 | $ret->params = array_intersect_key( $this->params, array_fill_keys( $params, 1 ) ); |
| 102 | return $ret; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @codeCoverageIgnore |
| 107 | */ |
| 108 | public function __toString(): string { |
| 109 | $paramBits = []; |
| 110 | foreach ( $this->params as $k => $paramOffsets ) { |
| 111 | $paramBits[] = "$k: { " . $paramOffsets->__toString() . ' }'; |
| 112 | } |
| 113 | return '[ ' . implode( ', ', $paramBits ) . ' ]'; |
| 114 | } |
| 115 | } |