| 91 | class ChainingDemo |
| 92 | { |
| 93 | public function demo(): void |
| 94 | { |
| 95 | $studio = new ScaffoldingChainingDemo(); |
| 96 | |
| 97 | // Fluent method chains — MUST NOT appear: calibrate() (protected) |
| 98 | $studio->brush->setSize('large')->setStyle('pointed')->stroke(); |
| 99 | |
| 100 | // Return type chains |
| 101 | $studio->brush->getCanvas()->title(); |
| 102 | |
| 103 | // Variable → method chain |
| 104 | $canvas = $studio->brush->getCanvas(); |
| 105 | $canvas->getBrush()->stroke(); |
| 106 | |
| 107 | // Deep property chain |
| 108 | $studio->canvas->easel->material; |
| 109 | $studio->canvas->easel->height(); |
| 110 | |
| 111 | // Null-safe chaining |
| 112 | $maybe = Brush::find(1); |
| 113 | $maybe?->getCanvas()?->title(); |
| 114 | |
| 115 | // Multi-line method chains |
| 116 | $studio->brush->setSize('large') |
| 117 | ->setStyle('pointed') |
| 118 | ->stroke(); |
| 119 | |
| 120 | // Variable assigned from chain |
| 121 | $directBrush = $studio->brush->getCanvas()->getBrush(); |
| 122 | $directBrush->stroke(); |
| 123 | |
| 124 | // (new Class())->method() |
| 125 | $fromNew = (new Canvas())->getBrush(); |
| 126 | $fromNew->stroke(); |
| 127 | |
| 128 | // Intermediate variable from property access |
| 129 | $easel = (new Canvas())->easel; |
| 130 | $easel->material; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |