Compare generators

@param ReferenceGeneratorInterface $a
@param ReferenceGeneratorInterface $b
558666
public function compareGenerators(ReferenceGeneratorInterface $a, ReferenceGeneratorInterface $b)
    {
        if ($a->getPriority() == $b->getPriority() ) {
            return 0;
        }
        return ($a->getPriority() < $b->getPriority()) ? 1 : -1;
    }
1348628
public function find(ReferenceableInterface $referenceable) {
        foreach( $this->generators->all() as $generator ) {
            if( $generator->canHandle($referenceable) ) {
                return $generator;
            }
        }
        
        return null;
    }
772688
function it_should_replace_input_message_references_by_reference_html_link($reference1, $reference2) {
        $reference1->getStartIndice()->willReturn(5);
        $reference1->getEndIndice()->willReturn(10);
        $reference1->getType()->willReturn(ReferenceType::USER);
        $reference1->getData()->willReturn(array(
            "id"          => 6844292,
            "name"        => "John Doe",
            "type"        => "user",
            "offset"      => 5,
            "length"      => 5
        ));

        $reference2->getStartIndice()->willReturn(12);
        $reference2->getEndIndice()->willReturn(17);
        $reference2->getType()->willReturn(ReferenceType::PAGE);
        $reference2->getData()->willReturn(array(
            "id"          => 32425,
            "name"        => "test",
            "type"        => "page",
            "offset"      => 5,
            "length"      => 5
        ));

        $this->format('test @jdoe, @test bar', [$reference2, $reference1])
            ->shouldReturn('test <a href="https://www.facebook.com/6844292" target="_blank">@jdoe</a>, <a href="https://www.facebook.com/32425" target="_blank">@test</a> bar');

        $this->format('foo #média bar', [])
            ->shouldReturn('foo <a href="https://www.facebook.com/hashtag/média" target="_blank">#média</a> bar');

        $this->format('foo http://test.com bar', [])
            ->shouldReturn('foo <a href="http://test.com" target="_blank">http://test.com</a> bar');
    }
376961
protected function intFloatCompare(NI $a, NI $b)
    {
        return $this->rationalCompare(
            RationalTypeFactory::fromFloat($a->asFloatType()),
            RationalTypeFactory::fromFloat($b->asFloatType())
        );
    }
566424
public function getIdGenerator(int $generatorType): GeneratorInterface
    {
        static $generators = [];
        if (isset($generators[$generatorType])) {
            return $generators[$generatorType];
        }

        switch ($generatorType) {
            case DocumentMetadata::GENERATOR_TYPE_NONE:
                $generator = new AssignedIdGenerator();
                break;

            case DocumentMetadata::GENERATOR_TYPE_AUTO:
                $generator = new IdentityGenerator();
                break;

            default:
                throw new \InvalidArgumentException('Unknown id generator type '.$generatorType);
        }

        return $generators[$generatorType] = $generator;
    }
263129
private function resolveReference(Reference $reference)
    {
        if (!ExternalReference::isValid($reference)) {
            return $reference;
        }

        return $this->transformReferenceToDefinition(new ExternalReference($reference));
    }
1246844
public static function getGeneratorElements(Generator $generator)
    {
        $elements = [];

        for (; $generator->valid(); $generator->next()) {
            $elements[] = $generator->current();
        }

        return $elements;
    }
1202898
protected function compare(string $a, string $b): int
    {
        global $sortOrder;

        $aIndex = array_search($a, $sortOrder);
        $bIndex = array_search($b, $sortOrder);
        if ($aIndex === false) {
            return -1;
        }

        if ($bIndex === false) {
            return 1;
        }

        return $aIndex - $bIndex;
    }
1262888
public function findElementtypesUsingReferenceElementtype(Elementtype $referenceElementtype)
    {
        $elementtypes = array();
        foreach ($this->elementtypeManager->findAll() as $elementtype) {
            if (!$elementtype->getStructure()->getRootNode()) {
                continue;
            }
            $rii = new \RecursiveIteratorIterator($elementtype->getStructure()->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($rii as $node) {
                /* @var $node ElementtypeStructureNode */
                if ($node->getReferenceElementtypeId() === $referenceElementtype->getId()) {
                    $elementtypes[] = $elementtype;
                    break;
                }
            }
        }

        return $elementtypes;
    }
1238339
@SuppressWarnings({"static-method", "checkstyle:npathcomplexity"})
	public void loadBuilderPreferences(GeneratorConfig2 generatorConfig, IProject context) {
		final IPreferenceStore preferenceStore = SARLPreferences.getSARLPreferencesFor(context);
		if (preferenceStore != null) {
			if (preferenceStore.contains(PREF_GENERATED_TEST_SOURCE_FOLDER)) {
				generatorConfig.setGeneratedTestSourceFolder(preferenceStore.getString(PREF_GENERATED_TEST_SOURCE_FOLDER));
			}
			if (preferenceStore.contains(PREF_GENERATE_INLINE)) {
				generatorConfig.setGenerateInlineAnnotation(preferenceStore.getBoolean(PREF_GENERATE_INLINE));
			}
			if (generatorConfig.isGenerateInlineAnnotation()
					&& preferenceStore.contains(PREF_USE_EXPRESSION_INTERPRETER)) {
				generatorConfig.setUseExpressionInterpreterForInlineAnnotation(preferenceStore.getBoolean(
						PREF_USE_EXPRESSION_INTERPRETER));
			}
			if (preferenceStore.contains(PREF_GENERATE_PURE)) {
				generatorConfig.setGeneratePureAnnotation(preferenceStore.getBoolean(PREF_GENERATE_PURE));
			}
			if (preferenceStore.contains(PREF_GENERATE_EQUALITY_TEST_FUNCTIONS)) {
				generatorConfig.setGenerateEqualityTestFunctions(preferenceStore.getBoolean(PREF_GENERATE_EQUALITY_TEST_FUNCTIONS));
			}
			if (preferenceStore.contains(PREF_GENERATE_TOSTRING_FUNCTIONS)) {
				generatorConfig.setGenerateToStringFunctions(preferenceStore.getBoolean(PREF_GENERATE_TOSTRING_FUNCTIONS));
			}
			if (preferenceStore.contains(PREF_GENERATE_CLONE_FUNCTIONS)) {
				generatorConfig.setGenerateCloneFunctions(preferenceStore.getBoolean(PREF_GENERATE_CLONE_FUNCTIONS));
			}
			if (preferenceStore.contains(PREF_GENERATE_SERIAL_NUMBER_FIELDS)) {
				generatorConfig.setGenerateSerialNumberFields(preferenceStore.getBoolean(PREF_GENERATE_SERIAL_NUMBER_FIELDS));
			}
		}
	}
605984
public static function same_symbol(PHP_ParserGenerator_Symbol $a, PHP_ParserGenerator_Symbol $b)
    {
        if ($a === $b) return 1;
        if ($a->type != self::MULTITERMINAL) return 0;
        if ($b->type != self::MULTITERMINAL) return 0;
        if ($a->nsubsym != $b->nsubsym) return 0;
        for ($i = 0; $i < $a->nsubsym; $i++) {
            if ($a->subsym[$i] != $b->subsym[$i]) return 0;
        }
        return 1;
    }
1198220
final public function compare($item1, $item2)
    {
        if (!$this->isReady()) {
            throw new \RuntimeException("The comparer is not ready, no valid callback has been set.");
        }

        return call_user_func_array($this->callback, [$item1, $item2, $this->options]);
    }
307927
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('ObjectState');
        $visitor->setHeader('Content-Type', $generator->getMediaType('ObjectState'));
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('ObjectStateUpdate'));

        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_loadObjectState',
                array('objectStateGroupId' => $data->groupId, 'objectStateId' => $data->objectState->id)
            )
        );
        $generator->endAttribute('href');

        $generator->startValueElement('id', $data->objectState->id);
        $generator->endValueElement('id');

        $generator->startValueElement('identifier', $data->objectState->identifier);
        $generator->endValueElement('identifier');

        $generator->startValueElement('priority', $data->objectState->priority);
        $generator->endValueElement('priority');

        $generator->startObjectElement('ObjectStateGroup');

        $generator->startAttribute(
            'href',
            $this->router->generate('ezpublish_rest_loadObjectStateGroup', array('objectStateGroupId' => $data->groupId))
        );
        $generator->endAttribute('href');

        $generator->endObjectElement('ObjectStateGroup');

        $generator->startValueElement('defaultLanguageCode', $data->objectState->defaultLanguageCode);
        $generator->endValueElement('defaultLanguageCode');

        $generator->startValueElement('languageCodes', implode(',', $data->objectState->languageCodes));
        $generator->endValueElement('languageCodes');

        $this->visitNamesList($generator, $data->objectState->getNames());
        $this->visitDescriptionsList($generator, $data->objectState->getDescriptions());

        $generator->endObjectElement('ObjectState');
    }
142375
public static function compareVersions($a, $b)
    {
        $versionPos = max(count($a), count($b));
        while (count($a) < $versionPos) {
            $a[] = 0;
        }
        while (count($b) < $versionPos) {
            $b[] = 0;
        }

        for ($v = 0; $v < count($a); $v++) {
            if ((int)$a[$v] < (int)$b[$v]) {
                return '<';
            }
            if ((int)$a[$v] > (int)$b[$v]) {
                return '>';
            }
        }
        return '=';
    }
323164
function compilationGenerator(eager, $compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext) {
      var compiled;

      if (eager) {
        return compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);
      }
      return function lazyCompilation() {
        if (!compiled) {
          compiled = compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);

          // Null out all of these references in order to make them eligible for garbage collection
          // since this is a potentially long lived closure
          $compileNodes = transcludeFn = previousCompileContext = null;
        }
        return compiled.apply(this, arguments);
      };
    }
936689
private static function compareQNames($a, $b) {
		$a_index = array_search($a, self::$attributes_order);
		$b_index = array_search($b, self::$attributes_order);

		if ($a_index !== false && $b_index !== false) {
			return $a_index - $b_index;
		}
		if ($a_index === false && $b_index === false) {
			return strcmp($a, $b);
		}
		return ($a_index === false) ? 1 : -1;
	}
89381
public function checkGenerated(): ?GeneratorVerifier
    {
        $cardinality = $this->resetCardinality();

        $calls = $this->spy->allCalls();
        $matchingEvents = [];
        $totalCount = count($calls);
        $matchCount = 0;

        foreach ($calls as $call) {
            if (!$call->responseEvent()) {
                continue;
            }

            list(, $returnValue) = $call->response();

            if ($returnValue instanceof Generator) {
                $matchingEvents[] = $call;
                ++$matchCount;
            }
        }

        if ($cardinality->matches($matchCount, $totalCount)) {
            return $this->assertionRecorder->createSuccessFromEventCollection(
                $this->generatorVerifierFactory
                    ->create($this->spy, $matchingEvents)
            );
        }

        return null;
    }