{"id":15753750,"url":"https://github.com/marella/code-guidelines","last_synced_at":"2026-01-11T02:37:58.170Z","repository":{"id":66207393,"uuid":"50169232","full_name":"marella/code-guidelines","owner":"marella","description":null,"archived":false,"fork":false,"pushed_at":"2016-01-22T08:48:20.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T12:15:57.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/marella/code-guidelines/blob/master/README.md#readme","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-22T08:46:41.000Z","updated_at":"2024-02-14T02:09:01.000Z","dependencies_parsed_at":"2023-04-18T17:30:33.703Z","dependency_job_id":null,"html_url":"https://github.com/marella/code-guidelines","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fcode-guidelines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fcode-guidelines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fcode-guidelines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fcode-guidelines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marella","download_url":"https://codeload.github.com/marella/code-guidelines/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246436052,"owners_count":20776960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-04T07:41:55.521Z","updated_at":"2026-01-11T02:37:58.164Z","avatar_url":"https://github.com/marella.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"### Table of contents\n- [Development](#development)\n- [Coding](#coding)\n- [PHP](#php)\n- [MySQL](#mysql)\n- [HTML](#html)\n- [CSS](#css)\n- [JS](#js)\n- [Icons](#icons)\n\n### Development\n- Divide large applications into smaller independent components\n- Each component should do one thing and do it well ([Microservices](https://en.wikipedia.org/wiki/Microservices))\n- Do NOT mix UI and backend code ([MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller))\n- Keep separate copies for development, testing and production\n- Use git for version control\n- See https://sethrobertson.github.io/GitBestPractices/\n\n### Coding\n- Use tabs for indentation (different projects have different conventions but we use tabs)\n- Trim trailing white space\n- Add new line at end of files\n- Split long lines\n- Split large files (more files are better for collaboration and version control)\n- Use descriptive names for variables and functions\n- Avoid global variables\n- Use [Sublime Text](http://www.sublimetext.com/) with these settings\n\n```json\n{\n\t\"detect_indentation\": false,\n\t\"ensure_newline_at_eof_on_save\": true,\n\t\"font_size\": 14.0,\n\t\"ignored_packages\":\n\t[\n\t\t\"Vintage\"\n\t],\n\t\"open_files_in_new_window\": false,\n\t\"scroll_past_end\": true,\n\t\"shift_tab_unindent\": true,\n\t\"tab_size\": 4,\n\t\"translate_tabs_to_spaces\": false,\n\t\"trim_trailing_white_space_on_save\": true,\n\t\"word_wrap\": false\n}\n```\n\n### PHP\n- One class per file\n- Always use namespaces\n- Class filenames should be same as class name (case-sensitive) and should be loaded using autoloading functions\n- Other filenames should be in lowercase\n- In a file either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but do NOT do both\n- Do NOT put closing PHP tag `?\u003e` at the end of file\n- Turn on all errors and notices during development\n- Avoid static methods\n- Follow [functional programming](https://en.wikipedia.org/wiki/Functional_programming) whenever possible\n- See [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/) standards\n\n```php\n\u003c?php\nnamespace Vendor\\Package;\n\nuse FooInterface;\nuse BarClass as Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass Foo extends Bar implements FooInterface\n{\n\tpublic function sampleFunction($a, $b = null)\n\t{\n\t\tif ($a === $b) {\n\t\t\tbar();\n\t\t} elseif ($a \u003e $b) {\n\t\t\t$foo-\u003ebar($arg1);\n\t\t} else {\n\t\t\tBazClass::bar($arg2, $arg3);\n\t\t}\n\t}\n\n\tfinal public static function bar()\n\t{\n\t\t// method body\n\t}\n}\n```\n\n### MySQL\n- Use `PDO`\n- Add primary key to all tables\n- Use `LIMIT` in all statements whenever possible\n- Use descriptive names for tables and columns\n- Prefix table names with app name whenever possible\n- Avoid database names in statements to make it more portable\n- Cache results in memory (Redis) as DB operations are slow\n- Put database schema under version control\n\n```sql\nSELECT id FROM users WHERE email = ? LIMIT 1\nUPDATE users SET status = :status WHERE id = :id LIMIT 1\n```\n\n### HTML\n- Place all styles at top in head and scripts at the end of body\n- Do NOT use inline styles or scripts\n- Avoid generating HTML in JS\n- Avoid IDs and use only classes for styling\n- Combine, minify and optimize assets\n- See http://codeguide.co/#html\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cmeta charset=\"utf-8\"\u003e\n\t\t\u003cmeta http-equiv=\"x-ua-compatible\" content=\"ie=edge\"\u003e\n\t\t\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\t\t\u003ctitle\u003e\u003c/title\u003e\n\t\t\u003clink rel=\"stylesheet\" href=\"css/app.min.css\"\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\n\t\t\u003c!-- content --\u003e\n\n\t\t\u003cscript src=\"js/app.min.js\"\u003e\u003c/script\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### CSS\n- Do NOT use `@import`\n- Reduce specificity\n- Avoid using ID or tag selectors\n- Classes should be lowercase\n- Use hyphens and do NOT use underscores or camelCases in class names\n- Bootstrap like naming convention\n- Use Bootstrap whenever possible\n- See http://codeguide.co/#css\n\n```css\n.table {\n\tmargin-bottom: 15px;\n}\n\n.card {\n\tpadding: 20px;\n}\n\n.card-title {\n\tfont-size: 18px;\n}\n\n.card-primary {\n\tbackground-color: #abcdef;\n}\n```\n\n### JS\n- Use camelCase for variable and function names\n- Cache jQuery lookups `var $this = $(this);`\n- Use jQuery whenever possible\n- See https://github.com/airbnb/javascript/tree/master/es5\n\n```js\n!function(global) {\n\t'use strict';\n\n\tvar previousFancyInput = global.FancyInput;\n\n\tfunction FancyInput(options) {\n\t\tthis.options = options || {};\n\t}\n\n\tFancyInput.noConflict = function noConflict() {\n\t\tglobal.FancyInput = previousFancyInput;\n\t\treturn FancyInput;\n\t};\n\n\tglobal.FancyInput = FancyInput;\n}(this);\n```\n\n### Icons\n- Use icon font\n- See https://icomoon.io/app/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarella%2Fcode-guidelines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarella%2Fcode-guidelines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarella%2Fcode-guidelines/lists"}