Code Duplication    Length = 29-30 lines in 2 locations

src/PhpSpreadsheet/Calculation/Engineering.php 2 locations

@@ 1195-1224 (lines=30) @@
1192
     *                                If places is negative, BIN2HEX returns the #NUM! error value.
1193
     * @return    string
1194
     */
1195
    public static function BINTOHEX($x, $places = null)
1196
    {
1197
        $x = Functions::flattenSingleValue($x);
1198
        $places = Functions::flattenSingleValue($places);
1199
1200
        // Argument X
1201
        if (is_bool($x)) {
1202
            if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
1203
                $x = (int) $x;
1204
            } else {
1205
                return Functions::VALUE();
1206
            }
1207
        }
1208
        if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
1209
            $x = floor($x);
1210
        }
1211
        $x = (string) $x;
1212
        if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1213
            return Functions::NAN();
1214
        }
1215
        if (strlen($x) > 10) {
1216
            return Functions::NAN();
1217
        } elseif (strlen($x) == 10) {
1218
            //    Two's Complement
1219
            return str_repeat('F', 8) . substr(strtoupper(dechex(bindec(substr($x, -9)))), -2);
1220
        }
1221
        $hexVal = (string) strtoupper(dechex(bindec($x)));
1222
1223
        return self::nbrConversionFormat($hexVal, $places);
1224
    }
1225
1226
    /**
1227
     * BINTOOCT
@@ 1249-1277 (lines=29) @@
1246
     *                                If places is negative, BIN2OCT returns the #NUM! error value.
1247
     * @return    string
1248
     */
1249
    public static function BINTOOCT($x, $places = null)
1250
    {
1251
        $x = Functions::flattenSingleValue($x);
1252
        $places = Functions::flattenSingleValue($places);
1253
1254
        if (is_bool($x)) {
1255
            if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
1256
                $x = (int) $x;
1257
            } else {
1258
                return Functions::VALUE();
1259
            }
1260
        }
1261
        if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
1262
            $x = floor($x);
1263
        }
1264
        $x = (string) $x;
1265
        if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1266
            return Functions::NAN();
1267
        }
1268
        if (strlen($x) > 10) {
1269
            return Functions::NAN();
1270
        } elseif (strlen($x) == 10) {
1271
            //    Two's Complement
1272
            return str_repeat('7', 7) . substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
1273
        }
1274
        $octVal = (string) decoct(bindec($x));
1275
1276
        return self::nbrConversionFormat($octVal, $places);
1277
    }
1278
1279
    /**
1280
     * DECTOBIN