src/Callbacks/OptionValueAndSwatchHandler.php
protected function createOptionByValueIfNecessary($entityTypeId, $attributeCode, $storeId, $value)
    {

        // initialize the option ID
        $optionId = 0;

        // try to load the attribute option by the given attribute code, store ID + value
        if ($attributeOption = $this->loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)) {
            // set the ID of the loaded option
            $optionId = $attributeOption[MemberNames::OPTION_ID];
        } else {
            // create a new option and set the ID
            $optionId = $this->persistAttributeOption($this->prepareAttributeOption($entityTypeId, $attributeCode));
            // log a message that a new option has been created
            $this->getSystemLogger()->info(sprintf('Successfully created new option for attribute with code "%s"', $attributeCode));
        }

        // return the option ID
        return $optionId;
    }
protected function createOptionByValueIfNecessary($entityTypeId, $attributeCode, $storeId, $value)
    {

        // initialize the option ID
        $optionId = 0;

        // try to load the attribute option by the given attribute code, store ID + value
        if ($attributeOption = $this->loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)) {
            // set the ID of the loaded option
            $optionId = $attributeOption[MemberNames::OPTION_ID];
        } else {
            // create a new option and set the ID
            $optionId = $this->persistAttributeOption($this->prepareAttributeOption($entityTypeId, $attributeCode));
            // log a message that a new option has been created
            $this->getSystemLogger()->info(sprintf('Successfully created new option for attribute with code "%s"', $attributeCode));
        }

        // return the option ID
        return $optionId;
    }
Queries whether or not an option for the attribute with the given code already exists.
If not the option and/or the swatch/value will be created dynamically.

@param integer $entityTypeId  The entity type ID of the option to create
@param string  $attributeCode The attribute code to create the option as well as the swatch/value for
@param integer $storeId       The store ID
@param mixed   $value         The store specific option swatch/value

@return integer The ID of the option