Get the extension from MediaAlchemyst specs

@param SpecificationInterface $spec

@return string
502568
private function getExtensionFromSpec(SpecificationInterface $spec)
    {
        switch ($spec->getType()) {
            case SpecificationInterface::TYPE_IMAGE:
                return $this->getExtensionFromImageCodec($spec->getImageCodec());
            case SpecificationInterface::TYPE_ANIMATION:
                return 'gif';
            case SpecificationInterface::TYPE_AUDIO:
                return $this->getExtensionFromAudioCodec($spec->getAudioCodec());
            case SpecificationInterface::TYPE_VIDEO:
                return $this->getExtensionFromVideoCodec($spec->getVideoCodec());
            case SpecificationInterface::TYPE_SWF:
                return 'swf';
            case PdfSpecification::TYPE_PDF:
                return 'pdf';
        }

        return null;
    }
1156781
protected function getForceFormatOptions(FormatInterface $format)
	{
		$formatExtensions = $format->getExtensions();
		
		if (count($formatExtensions) > 0)
		{
			if ( ! file_exists(__DIR__.'/../../bin/ffmpeg_fmt.php'))
			{
				return [];
			}
			
			$ffmpeg_fmt = (array) require __DIR__.'/../../bin/ffmpeg_fmt.php';
			
			foreach ($ffmpeg_fmt as $format_string => $extensions)
			{
				if (array_intersect($formatExtensions, $extensions))
				{
					return ['force_format' => $format_string];
				}
			}
		}
		
		return [];
	}
1198543
private function prepare(
        SpecificationInterface $specification,
        EntityManager $entityManager,
        QueryBuilder $queryBuilder,
        AbstractQuery $query
    ) {
        $entityManager->createQueryBuilder()->willReturn($queryBuilder);

        $specification->modify($queryBuilder, $this->dqlAlias)->willReturn($this->expression);

        $queryBuilder->select($this->dqlAlias)->willreturn($queryBuilder);
        $queryBuilder->from(Argument::any(), $this->dqlAlias, Argument::any())->willReturn($queryBuilder);
        $queryBuilder->where($this->expression)->willReturn($queryBuilder);

        $queryBuilder->getQuery()->willReturn($query);

        $query->execute()->willReturn($this->result);
    }
926396
public function getBuilder(AbstractModel $model): ?AbstractBuilder {
		if ($model instanceof PhpClass) {
			return $this->classBuilder;
		}

		if ($model instanceof PhpConstant) {
			return $this->constantBuilder;
		}

		if ($model instanceof PhpFunction) {
			return $this->functionBuilder;
		}

		if ($model instanceof PhpInterface) {
			return $this->interfaceBuilder;
		}

		if ($model instanceof PhpMethod) {
			return $this->methodBuilder;
		}

		if ($model instanceof PhpParameter) {
			return $this->parameterBuilder;
		}

		if ($model instanceof PhpProperty) {
			return $this->propertyBuilder;
		}

		if ($model instanceof PhpTrait) {
			return $this->traitBuilder;
		}

		return null;
	}
937970
public function convertSimpleSpec($spec) {
    if (($year = Preg::qmatch($spec,'/^([0-9]+) YEARs?/i',1,FALSE)) !== FALSE) {
      return sprintf('P%dY',$year);
    }

    if (($day = Preg::qmatch($spec,'/^([0-9]+) DAYs?/i',1,FALSE)) !== FALSE) {
      return sprintf('P%dD',$day);
    }
    
    return $spec;
  }
1343300
public function convert($inFilename, Specification $spec, $outFilename)
    {
        $audio = $this->ffmpeg->open($inFilename);

        $format = $this->createFormat($spec->getAudioFormat());

        if ($spec->getAudioCodec()) {
            $format->setAudioCodec($spec->getAudioCodec());
        }

        if ($spec->getAudioBitrate()) {
            $format->setAudioKiloBitrate($spec->getAudioBitrate());
        }

        if ($spec->getAudioSamplerate()) {
            $audio->addFilter(new AudioResamplableFilter($spec->getAudioSamplerate()));
        }

        if ($spec->getAudioChannels()) {
            $format->setAudioChannels($spec->getAudioChannels());
        }

        $audio->save($format, $outFilename);
    }
26322
private function extractFieldType($spec)
    {
        if (!preg_match('/(\w+)(?:\s*\(\s*([0-9]+)(?:\,\s*([0-9]+))?\s*\))?(?:\s*(\w+))?/s', strtoupper($spec), $match)) {
            return [null, null, null, null];
        }

        $dbType   = isset($match[1]) ? $match[1] : null;
        $size     = isset($match[2]) && $match[2] != '' ? (int)$match[2] : null;
        $scale    = isset($match[3]) && $match[2] != '' ? (int)$match[3] : null;
        $unsigned = isset($match[4]) && $match[4] == 'UNSIGNED';

        return [$dbType, $size, $scale, $unsigned];
    }
682637
public function getIdentity($spec = null, $default = null)
    {
        if ($spec !== null) {
            return isset($this->identity[$spec]) ? $this->identity[$spec] : $default;
        } else {
            return $this->identity;
        }
    }
884507
final public function whereHasAll(string $collectionMemberExpression, ISpecification $specification)
    {
        return $this->where($collectionMemberExpression, ConditionOperator::ALL_SATISFIES, $specification);
    }
573383
@SuppressWarnings("StringSplitter")
  public static @NonNull CaffeineSpec parse(@NonNull String specification) {
    CaffeineSpec spec = new CaffeineSpec(specification);
    for (String option : specification.split(SPLIT_OPTIONS)) {
      spec.parseOption(option.trim());
    }
    return spec;
  }
10287
private function validate(Specification $spec)
    {
        if ($spec instanceof Not || $spec instanceof AndX || $spec instanceof OrX) {
            throw new \InvalidArgumentException('Algolia does not allows to negate a group');
        }
    }
1344997
protected function getFormatOptions(FormatInterface $format)
	{
		$options = $format->getOptions();
		
		if ($format instanceof AudioFormatInterface)
		{
			$options['audio_codec'] = (string) $format->getAudioCodec() ?: 'copy';
			
			if ($format->getAudioBitrate() > 0)
			{
				$options['audio_bitrate'] = $format->getAudioBitrate();
			}
			
			if ($format->getFrequency() > 0)
			{
				$options['audio_sample_frequency'] = $format->getFrequency();
			}
			
			if ($format->getChannels() > 0)
			{
				$options['audio_channels'] = $format->getChannels();
			}
		}
		
		if ($format instanceof FrameFormatInterface)
		{
			$options['video_codec'] = (string) $format->getVideoCodec() ?: 'copy';
		}
		
		if ($format instanceof VideoFormatInterface)
		{
			if ($format->getFrameRate() > 0)
			{
				$options['video_frame_rate'] = $format->getFrameRate();
			}
			
			if ($format->getVideoBitrate() > 0)
			{
				$options['video_bitrate'] = $format->getVideoBitrate();
			}
			
			$options['movflags'] = '+faststart';
		}
		
		return $options;
	}
925907
protected function generateGetExtensionsMethod(Entity $entity)
    {
        $lines      = [];
        $descriptor = $entity->getDescriptor();
        $fieldName  = $this->getUniqueFieldName($descriptor, 'extensions');

        $lines[] = 'if ( $this->' . $fieldName . ' !== null) {';
        $lines[] = '    return $this->' . $fieldName . ';';
        $lines[] = '}';
        $lines[] = null;
        $lines[] = 'return $this->' . $fieldName . ' = new \Protobuf\Extension\ExtensionFieldMap(__CLASS__);';

        return MethodGenerator::fromArray([
            'name'       => 'extensions',
            'body'       => implode(PHP_EOL, $lines),
            'docblock'   => [
                'shortDescription' => "{@inheritdoc}"
            ]
        ]);
    }
1134249
protected function formatCallable(array $specs)
    {
        if (isset($specs['can'])) {
            $callback = json_encode($specs['can']);

            return "Gate::check({$callback})";
        }

        if (! isset($specs['do'])) {
            return '';
        }

        $callback = $specs['do'];

        if ($callback instanceof \Closure) {
            return 'Closure';
        }

        if (is_string($callback)) {
            if (strpos($callback, '@') !== false) {
                $callback = explode('@', $callback);
            } else {
                return $callback.'()';
            }
        }

        if (is_array($callback)) {
            return implode('::', $callback).'()';
        }

        return $callback;
    }
668548
public function afterSpec(Spec $spec)
    {
        $leftPad = str_repeat(' ', self::TAB_SIZE * $this->depth);

        if ($spec->isFailed()) {
            $this->failures[] = $spec;
            $title = $this->formatter->red($spec->getTitle());
        } elseif ($spec->isIncomplete()) {
            $this->incompleteSpecs[] = $spec;
            $title = $this->formatter->cyan($spec->getTitle());
        } elseif ($spec->isPending()) {
            $this->pendingSpecs[] = $spec;
            $title = $this->formatter->yellow($spec->getTitle());
        } else {
            $title = $this->formatter->grey($spec->getTitle());
        }

        $this->console->writeLn($leftPad . $title);
    }
728372
final public static function specToSeconds($spec)
    {
        if (!empty($spec)) {
            if (is_string($spec) && (($spec[0] == "P") || ($spec[0] == "p"))) {
                $spec = strtoupper($spec);
                $interval = new \DateInterval($spec);
                return self::intervalToSeconds($interval);
            } else {
                return intval($spec);
            }
        }

        return 0;
    }
210390
public function handle(SpecificationInterface $specification): Generator
    {
        foreach ($this->yieldFilesInPath($specification, '') as $path) {
            if (isset($path['type']) && $path['type'] === 'file') {
                yield $path;
            }
        }
    }