Complex classes like Script often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Script, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 14 | class Script extends Serializable implements ScriptInterface  | 
            ||
| 15 | { | 
            ||
| 16 | |||
| 17 | /**  | 
            ||
| 18 | * @var Opcodes  | 
            ||
| 19 | */  | 
            ||
| 20 | protected $opCodes;  | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * @var string  | 
            ||
| 24 | */  | 
            ||
| 25 | protected $script;  | 
            ||
| 26 | |||
| 27 | /**  | 
            ||
| 28 | * @param BufferInterface $script  | 
            ||
| 29 | * @param Opcodes|null $opCodes  | 
            ||
| 30 | */  | 
            ||
| 31 | 5600 | public function __construct(BufferInterface $script = null, Opcodes $opCodes = null)  | 
            |
| 36 | |||
| 37 | /**  | 
            ||
| 38 | * @return BufferInterface  | 
            ||
| 39 | */  | 
            ||
| 40 | 5648 | public function getBuffer()  | 
            |
| 44 | |||
| 45 | /**  | 
            ||
| 46 | * @return Parser  | 
            ||
| 47 | */  | 
            ||
| 48 | 5132 | public function getScriptParser()  | 
            |
| 52 | |||
| 53 | /**  | 
            ||
| 54 | * Get all opcodes  | 
            ||
| 55 | *  | 
            ||
| 56 | * @return Opcodes  | 
            ||
| 57 | */  | 
            ||
| 58 | 18 | public function getOpCodes()  | 
            |
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Return a buffer containing the hash of this script.  | 
            ||
| 65 | *  | 
            ||
| 66 | * @return BufferInterface  | 
            ||
| 67 | */  | 
            ||
| 68 | 48 | public function getScriptHash()  | 
            |
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * @return BufferInterface  | 
            ||
| 75 | */  | 
            ||
| 76 | 78 | public function getWitnessScriptHash()  | 
            |
| 80 | |||
| 81 | /**  | 
            ||
| 82 | * @param bool|true $accurate  | 
            ||
| 83 | * @return int  | 
            ||
| 84 | */  | 
            ||
| 85 | 48 | public function countSigOps($accurate = true)  | 
            |
| 114 | |||
| 115 | /**  | 
            ||
| 116 | * @param WitnessProgram $program  | 
            ||
| 117 | * @param ScriptWitnessInterface $scriptWitness  | 
            ||
| 118 | * @return int  | 
            ||
| 119 | */  | 
            ||
| 120 | private function witnessSigOps(WitnessProgram $program, ScriptWitnessInterface $scriptWitness)  | 
            ||
| 136 | |||
| 137 | /**  | 
            ||
| 138 | * @param ScriptInterface $scriptSig  | 
            ||
| 139 | * @param ScriptWitnessInterface $scriptWitness  | 
            ||
| 140 | * @param int $flags  | 
            ||
| 141 | * @return int  | 
            ||
| 142 | */  | 
            ||
| 143 | public function countWitnessSigOps(ScriptInterface $scriptSig, ScriptWitnessInterface $scriptWitness, $flags)  | 
            ||
| 166 | |||
| 167 | /**  | 
            ||
| 168 | * @param ScriptInterface $scriptSig  | 
            ||
| 169 | * @return int  | 
            ||
| 170 | */  | 
            ||
| 171 | 165 | public function countP2shSigOps(ScriptInterface $scriptSig)  | 
            |
| 198 | |||
| 199 | /**  | 
            ||
| 200 | * @return bool  | 
            ||
| 201 | */  | 
            ||
| 202 | 268 | public function isPushOnly()  | 
            |
| 212 | |||
| 213 | /**  | 
            ||
| 214 | * @param WitnessProgram|null $program  | 
            ||
| 215 | * @return bool  | 
            ||
| 216 | */  | 
            ||
| 217 | 181 | public function isWitness(& $program = null)  | 
            |
| 243 | |||
| 244 | /**  | 
            ||
| 245 | * @param ScriptInterface $script  | 
            ||
| 246 | * @return bool  | 
            ||
| 247 | */  | 
            ||
| 248 | 334 | public function equals(ScriptInterface $script)  | 
            |
| 252 | |||
| 253 | /**  | 
            ||
| 254 | * @return string  | 
            ||
| 255 | */  | 
            ||
| 256 | public function __debugInfo()  | 
            ||
| 268 | }  | 
            ||
| 269 |