<commit_before><?php

namespace BetterReflection\Reflection;

use BetterReflection\TypesFinder\FindPropertyType;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property as PropertyNode;
use phpDocumentor\Reflection\Type;

class ReflectionProperty implements \Reflector
{
    const IS_PUBLIC = 1;
    const IS_PROTECTED = 2;
    const IS_PRIVATE = 3;

    /**
     * @var string
     */
    private $name;

    /**
     * @var int
     */
    private $visibility;

    /**
     * @var bool
     */
    private $isStatic;

    /**
     * @var Type[]
     */
    private $docBlockTypes;

    /**
     * @var ReflectionClass
     */
    private $declaringClass;

    /**
     * @var string
     */
    private $docBlock = '';

    /**
     * @var bool
     */
    private $isRuntimeDeclared = false;

    private function __construct()
    {
    }

    public static function export()
    {
        throw new \Exception('Unable to export statically');
    }

    /**
     * Return string representation of this little old property
     *
     * @return string
     */
    public function __toString()
    {
        return sprintf(
            'Property [%s %s%s $%s ]',
            $this->isStatic() ? '' : ($this->isDefault() ? ' <default>' : ' <implicit>'),
            $this->getVisibilityAsString(),
            $this->isStatic() ? ' static' : '',
            $this->getName()
        );
    }

    /**
     * @param PropertyNode $node
     * @param ReflectionClass $declaringClass
     * @return ReflectionProperty
     */
    public static function createFromNode(
        PropertyNode $node,
        ReflectionClass $declaringClass
    ) {
        $prop = new self();
        $prop->name = $node->props[0]->name;
        $prop->declaringClass = $declaringClass;

        if ($node->hasAttribute('comments')) {
            /* @var \PhpParser\Comment\Doc $comment */
            $comment = $node->getAttribute('comments')[0];
            $prop->docBlock = $comment->getReformattedText();
        }

        if ($node->isPrivate()) {
            $prop->visibility = self::IS_PRIVATE;
        } elseif ($node->isProtected()) {
            $prop->visibility = self::IS_PROTECTED;
        } else {
            $prop->visibility = self::IS_PUBLIC;
        }

        $prop->isStatic = $node->isStatic();

        $prop->docBlockTypes = (new FindPropertyType())->__invoke($prop);

        return $prop;
    }

    /**
     * @return string
     */
    private function getVisibilityAsString()
    {
        switch ($this->visibility) {
            case self::IS_PROTECTED:
                return 'protected';
            case self::IS_PRIVATE:
                return 'private';
            default:
                return 'public';
        }
    }

    /**
     * Has the property been declared at runtime (rather than compile-time?)
     *
     * @return bool
     */
    public function isDefault()
    {
        if ($this->isStatic()) {
            return false;
        }

        return !$this->isRuntimeDeclared;
    }

    /**
     * Get the core-reflection-compatible modifier values
     *
     * @return int
     */
    public function getModifiers()
    {
        $val = 0;
        $val += $this->isStatic() ? \ReflectionProperty::IS_STATIC : 0;
        $val += $this->isPublic() ? \ReflectionProperty::IS_PUBLIC : 0;
        $val += $this->isProtected() ? \ReflectionProperty::IS_PROTECTED : 0;
        $val += $this->isPrivate() ? \ReflectionProperty::IS_PRIVATE : 0;
        return $val;
    }

    /**
     * Get the name of the property<commit_msg>Clarified intent with commenting in the isDefault method<commit_after><?php

namespace BetterReflection\Reflection;

use BetterReflection\TypesFinder\FindPropertyType;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property as PropertyNode;
use phpDocumentor\Reflection\Type;

class ReflectionProperty implements \Reflector
{
    const IS_PUBLIC = 1;
    const IS_PROTECTED = 2;
    const IS_PRIVATE = 3;

    /**
     * @var string
     */
    private $name;

    /**
     * @var int
     */
    private $visibility;

    /**
     * @var bool
     */
    private $isStatic;

    /**
     * @var Type[]
     */
    private $docBlockTypes;

    /**
     * @var ReflectionClass
     */
    private $declaringClass;

    /**
     * @var string
     */
    private $docBlock = '';

    private function __construct()
    {
    }

    public static function export()
    {
        throw new \Exception('Unable to export statically');
    }

    /**
     * Return string representation of this little old property
     *
     * @return string
     */
    public function __toString()
    {
        return sprintf(
            'Property [%s %s%s $%s ]',
            $this->isStatic() ? '' : ($this->isDefault() ? ' <default>' : ' <implicit>'),
            $this->getVisibilityAsString(),
            $this->isStatic() ? ' static' : '',
            $this->getName()
        );
    }

    /**
     * @param PropertyNode $node
     * @param ReflectionClass $declaringClass
     * @return ReflectionProperty
     */
    public static function createFromNode(
        PropertyNode $node,
        ReflectionClass $declaringClass
    ) {
        $prop = new self();
        $prop->name = $node->props[0]->name;
        $prop->declaringClass = $declaringClass;

        if ($node->hasAttribute('comments')) {
            /* @var \PhpParser\Comment\Doc $comment */
            $comment = $node->getAttribute('comments')[0];
            $prop->docBlock = $comment->getReformattedText();
        }

        if ($node->isPrivate()) {
            $prop->visibility = self::IS_PRIVATE;
        } elseif ($node->isProtected()) {
            $prop->visibility = self::IS_PROTECTED;
        } else {
            $prop->visibility = self::IS_PUBLIC;
        }

        $prop->isStatic = $node->isStatic();

        $prop->docBlockTypes = (new FindPropertyType())->__invoke($prop);

        return $prop;
    }

    /**
     * @return string
     */
    private function getVisibilityAsString()
    {
        switch ($this->visibility) {
            case self::IS_PROTECTED:
                return 'protected';
            case self::IS_PRIVATE:
                return 'private';
            default:
                return 'public';
        }
    }

    /**
     * Has the property been declared at compile-time?
     *
     * Note that unless the property is static, this is hard coded to return
     * true, because we are unable to reflect instances of classes, therefore
     * we can be sure that all properties are always declared at compile-time.
     *
     * @return bool
     */
    public function isDefault()
    {
        if ($this->isStatic()) {
            return false;
        }

        return true;
    }

    /**
     * Get the core-reflection-compatible modifier values
     *
     * @return int
     */
    public function getModifiers()
    {
        $val = 0;
        $val += $this->isStatic() ? \ReflectionProperty::IS_STATIC : 0;
        $val += $this->isPublic() ? \ReflectionProperty::IS_PUBLIC : 0;
        $val += $this->isProtected() ? \ReflectionProperty::IS_PROTECTED : 0;
        $val += $this->isPrivate() ? \ReflectionProperty::IS_PRIVATE : 0;
        return $val;
    }

    /**
     * Get the name of the property
{'fraction_non_alphanumeric': 0.13202362961945321, 'fraction_numerical': 0.0027476301689792555, 'mean_word_length': 1.9143314651721377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 64, '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': '4538608', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2056, 'n_words': 474}