<commit_before><?php
/**
 * Author: davert
 * Date: 14.09.12
 *
 * Class Locator
 * Description: Provides basic methods for building complex CSS and XPath locators.
 *
 */

namespace Codeception\Util;
use Symfony\Component\CssSelector\CssSelector;
use Symfony\Component\CssSelector\XPathExpr;

class Locator
{

    /**
     * Applies OR operator to any number of CSS or XPath selectors.
     * You can mix up CSS and XPath selectors here.
     *
     * @static
     * @param $selector1
     * @param $selector2
     * @return string
     */
    public static function combine($selector1, $selector2) {
        $selectors = func_get_args();
        foreach ($selectors as $k => $v) {
            $selectors[$k] = self::toXPath($v);
        }
        return implode(' | ', $selectors);
    }

    /**
     * Matches the *a* element with given URL
     *
     * @static
     * @param $url
     * @return string
     */
    public static function href($url)
    {
        return sprintf('//a[@href=normalize-space(%s)]', XPathExpr::xpathLiteral($url));
    }

    /**
     * Matches the element with given tab index
     *
     * @static
     * @param $index
     * @return string
     */
    public static function tabIndex($index)
    {
        return sprintf('//*[@tabindex = normalize-space(%d)]', $index);
    }

    protected static function toXPath($selector)
    {
        try {
            $xpath = CssSelector::toXPath($selector);
        } catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {
            $xpath = $selector;
        }
        return $xpath;
    }

    /**
     * Finds element by it's attribute(s)
     *
     * @static
     * @param $element
     * @param $attributes
     * @return string
     */
    public static function find($element, array $attributes)
    {
        $operands = array();
        foreach ($attributes as $attribute => $value) {
            if (is_int($attribute)) {
                $operands[] = '@'.$value;
            } else {
                $operands[] = '@'.$attribute.' = '. XPathExpr::xpathLiteral($value);
            }
        }
        return sprintf('//%s[%s]', $element, implode(' and ', $operands));
    }



}<commit_msg>locator class updated to match symfony 2.3 changes in css component<commit_after><?php
/**
 * Author: davert
 * Date: 14.09.12
 *
 * Class Locator
 * Description: Provides basic methods for building complex CSS and XPath locators.
 *
 */

namespace Codeception\Util;
use Symfony\Component\CssSelector\CssSelector;
use Symfony\Component\CssSelector\Exception\ParseException;
use Symfony\Component\CssSelector\XPath\Translator;

class Locator
{

    /**
     * Applies OR operator to any number of CSS or XPath selectors.
     * You can mix up CSS and XPath selectors here.
     *
     * @static
     * @param $selector1
     * @param $selector2
     * @return string
     */
    public static function combine($selector1, $selector2) {
        $selectors = func_get_args();
        foreach ($selectors as $k => $v) {
            $selectors[$k] = self::toXPath($v);
        }
        return implode(' | ', $selectors);
    }

    /**
     * Matches the *a* element with given URL
     *
     * @static
     * @param $url
     * @return string
     */
    public static function href($url)
    {
        return sprintf('//a[@href=normalize-space(%s)]', Translator::getXpathLiteral($url));
    }

    /**
     * Matches the element with given tab index
     *
     * @static
     * @param $index
     * @return string
     */
    public static function tabIndex($index)
    {
        return sprintf('//*[@tabindex = normalize-space(%d)]', $index);
    }

    protected static function toXPath($selector)
    {
        try {
            $xpath = CssSelector::toXPath($selector);
        } catch (ParseException $e) {
            $xpath = $selector;
        }
        return $xpath;
    }

    /**
     * Finds element by it's attribute(s)
     *
     * @static
     * @param $element
     * @param $attributes
     * @return string
     */
    public static function find($element, array $attributes)
    {
        $operands = array();
        foreach ($attributes as $attribute => $value) {
            if (is_int($attribute)) {
                $operands[] = '@'.$value;
            } else {
                $operands[] = '@'.$attribute.' = '. Translator::getXpathLiteral($value);
            }
        }
        return sprintf('//%s[%s]', $element, implode(' and ', $operands));
    }



}
{'fraction_non_alphanumeric': 0.1360392506690455, 'fraction_numerical': 0.004906333630686887, 'mean_word_length': 2.093103448275862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4418601', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1337, 'n_words': 336}