def add_constructor(self, prop_name):
        'Add constructor argument and setter.'
        constructor = self.view.find(r'__construct\s*\(', 0)

        if constructor:
            constructor_start = constructor.end()
            constructor_end = self.view.find(r'\)', constructor_start).begin()
        # create the constructor if it does not exist
        else:
            text = "\n\tpublic function __construct()\n\t{\n\t}"
            properties = self.find_properties()

            # if the class has any properties, insert an extra newline and put
            # the constructor right after the last property
            if properties:
                pos = properties[-1].end()
                text = "\n" + text
            # otherwise, find the opening { of the class and put it there
            else:
                pos = self.find_class_opening_bracket()

            self.view_insert(pos, text)

            # easier than calculating the positions
            constructor = self.view.find(r'__construct\s*\(\)', 0)
            constructor_start = constructor_end = constructor.end() - 1

        constructor_args = self.view.substr(sublime.Region(constructor_start, constructor_end))
        arg_pos = constructor_end
        text = "$" + prop_name

        # figure out if the constructor is multiline
        last_newline = self.view.find_by_class(constructor_end, False, sublime.CLASS_LINE_END)
        last_word = self.view.find_by_class(constructor_end, False, sublime.CLASS_SUB_WORD_START)
        is_multiline_constructor = last_newline > last_word

        if is_multiline_constructor:
            arg_pos = last_newline

            # append a comma if there are any other arguments
            if constructor_args.strip() != '':
                arg_pos += self.view_insert(arg_pos, ",")

            # insert a newline and indent before inserting the argument
            arg_pos += self.view_insert(arg_pos, "\n\t\t")
            cursor_start = arg_pos + 1
        else:
            # when substitution is done, cursor will be past the point where the
            # closing parenthesis of the constructor currently is
            cursor_start = constructor_end + 1

            # prepend a comma if there are any other arguments
            if constructor_args.strip() != '':
                text = ", " + text
                cursor_start += 2

        # insert and add selection for the constructor argument name
        self.view_insert(arg_pos, text)
        cursor_end = cursor_start + len(prop_name)
        self.add_region(cursor_start, cursor_end)

        # add the line of code that sets the property
        constructor_close = self.view.find(r'\}', constructor_end).begin()
        last_newline = self.view.find_by_class(constructor_close, False, sublime.CLASS_LINE_START)
        cursor_start = last_newline + self.view_insert(last_newline, "\t\t$this->")
        self.view_insert(cursor_start, prop_name+' = $'+prop_name+";\n")

        # add selection for the property name
        cursor_end = cursor_start + len(prop_name)
        self.add_region(cursor_start, cursor_end)

        # add selection for the variable name
        cursor_start = cursor_end + 4
        cursor_end = cursor_start + len(prop_name)
        self.add_region(cursor_start, cursor_end)
dataset/ETHPy150Open erichard/SublimePHPCompanion/php_companion/commands/insert_php_constructor_property.py/InsertPhpConstructorPropertyCommand.add_constructor/original