1<?php 2 3/** 4 * FINE granularity DIFF 5 * 6 * Computes a set of instructions to convert the content of 7 * one string into another. 8 * 9 * Originally created by Raymond Hill (https://github.com/gorhill/PHP-FineDiff), brought up 10 * to date by Cog Powered (https://github.com/cogpowered/FineDiff). 11 * 12 * @copyright Copyright 2011 (c) Raymond Hill (http://raymondhill.net/blog/?p=441) 13 * @copyright Copyright 2013 (c) Robert Crowe (http://cogpowered.com) 14 * @link https://github.com/cogpowered/FineDiff 15 * @version 0.0.1 16 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) 17 */ 18 19namespace cogpowered\FineDiff\Parser\Operations; 20 21/** 22 * Generates the opcode for a copy operation. 23 */ 24class Copy implements OperationInterface 25{ 26 /** 27 * Set the initial length. 28 * 29 * @param int $len Length of string. 30 */ 31 public function __construct($len) 32 { 33 $this->len = $len; 34 } 35 36 /** 37 * @inheritdoc 38 */ 39 public function getFromLen() 40 { 41 return $this->len; 42 } 43 44 /** 45 * @inheritdoc 46 */ 47 public function getToLen() 48 { 49 return $this->len; 50 } 51 52 /** 53 * @inheritdoc 54 */ 55 public function getOpcode() 56 { 57 if ($this->len === 1) { 58 return 'c'; 59 } 60 61 return "c{$this->len}"; 62 } 63 64 /** 65 * Increase the length of the string. 66 * 67 * @param int $size Amount to increase the string length by. 68 * @return int New length 69 */ 70 public function increase($size) 71 { 72 return $this->len += $size; 73 } 74}