studpad/studpad

View on GitHub
app/assets/javascripts/components/post_box.js.jsx

Summary

Maintainability
F
1 wk
Test Coverage

File post_box.js.jsx has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const PostBox = React.createClass({
  //BEGIN***************************************************DECLARE
  propTypes: {
    group_id: React.PropTypes.number,
    //show_panel: React.PropTypes.boolean,
Severity: Minor
Found in app/assets/javascripts/components/post_box.js.jsx - About 3 hrs to fix

    Function createPost has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      createPost: function(postData) {
        var oldPosts = this.state.posts;
        var newPost = [{
          id: Date.now(),//random id for first
          type: postData.type,
    Severity: Minor
    Found in app/assets/javascripts/components/post_box.js.jsx - About 1 hr to fix

      Function createComment has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        createComment: function(post_id, text){
          CI('PostBox::createComment', post_id, text);
          var newPosts = this.state.posts.map(function (n) {
            if (n.id == post_id){
              n.comments.unshift({
      Severity: Minor
      Found in app/assets/javascripts/components/post_box.js.jsx - About 1 hr to fix

        Function likePost has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          likePost: function(id) {
            var posts = this.state.posts;
            var likedPost = $.grep(posts, function(e){ return e.id == id; });
            likedPost = likedPost[0];
            CI('PostBox::likePost', id);
        Severity: Minor
        Found in app/assets/javascripts/components/post_box.js.jsx - About 1 hr to fix

          Function removeComment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            removeComment: function(post_id, comment_id){
              CI('PostBox::removeComment', post_id, comment_id);
              var delete_url;
              var newPosts = this.state.posts.map(function (n) {
                if (n.id == post_id){
          Severity: Minor
          Found in app/assets/javascripts/components/post_box.js.jsx - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function updateComment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            updateComment: function(post_id, comment_id, text){
              CI('PostBox::removeComment', post_id, comment_id, text);
              var comment_url;
              var newPosts = this.state.posts.map(function (n) {
                if (n.id == post_id){
          Severity: Minor
          Found in app/assets/javascripts/components/post_box.js.jsx - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

            createComment: function(post_id, text){
              CI('PostBox::createComment', post_id, text);
              var newPosts = this.state.posts.map(function (n) {
                if (n.id == post_id){
                  n.comments.unshift({
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 1 day to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 136..166

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 250.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

            updateComment: function(post_id, comment_id, text){
              CI('PostBox::removeComment', post_id, comment_id, text);
              var comment_url;
              var newPosts = this.state.posts.map(function (n) {
                if (n.id == post_id){
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 1 day to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 57..82

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 200.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            loadPostsFromServer: function() {
              $.ajax({
                url: this.props.posts_url,
                dataType: 'json',
                data: {
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 7 hrs to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 15..37

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 187.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

            removeComment: function(post_id, comment_id){
              CI('PostBox::removeComment', post_id, comment_id);
              var delete_url;
              var newPosts = this.state.posts.map(function (n) {
                if (n.id == post_id){
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 7 hrs to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 38..56

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 175.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            componentDidMount: function() {
              this.loadPostsFromServer();
              $(window).scroll(function() {
                var scroll_part = $(window).scrollTop()/$(document).height();
                if (scroll_part > 0.8 && !this.state.limit_detected && !this.state.wait_posts ){
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 6 hrs to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 83..97

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 174.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              posts = posts.map(function(p){
                if (p.id == id){
                  if (p.current_like){
                    p.likes -= 1;
                    p.current_like = false;
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 1 other location - About 4 hrs to fix
          app/assets/javascripts/explore_grid.js.jsx on lines 110..123

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 120.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              $.ajax({
                url: likedPost.like_path,
                type: 'PUT',
                error: function(xhr, status, err) {
                  console.error(this.props.url, status, err.toString());
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 2 other locations - About 2 hrs to fix
          app/assets/javascripts/components/post_box.js.jsx on lines 242..248
          app/assets/javascripts/explore_grid.js.jsx on lines 125..131

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 75.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              $.ajax({
                url: thisPost.basket_path,
                type: 'PUT',
                error: function(xhr, status, err) {
                  console.error(this.props.url, status, err.toString());
          Severity: Major
          Found in app/assets/javascripts/components/post_box.js.jsx and 2 other locations - About 2 hrs to fix
          app/assets/javascripts/components/post_box.js.jsx on lines 216..222
          app/assets/javascripts/explore_grid.js.jsx on lines 125..131

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 75.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status